Figure 1 UploadFiles Method protected void UploadFilesThread() {
WebClient UploadObj = new WebClient();
object[] itemsCache = new object[fileListBox.Items.Count];
// Error out if we're asked to upload files that don't exist.
if (0 == fileListBox.Items.Count) {
ThrowWebException("You must browse for files before attempting an
upload.");
return;
}
// !TODO: Grant the ability to upload all files batch. WebClient
// doesn't support multiple files in the same upload txn, even
// though the standard does, so we'll roll our own classes later
// to handle this.
new FileIOPermission(PermissionState.Unrestricted).Assert();
fileListBox.Items.CopyTo(itemsCache, 0);
for (int i = 0; i < itemsCache.Length; i++) {
// Trap any failures.
try {
string item = (string)itemsCache[i]; // cast once
UploadObj.UploadFile(uploadURL, item);
// Remove from the list individually, in case
RemoveFile(item);
UpdateFileSizeDescription();
} catch (WebException e) {
ThrowWebException("Could not upload all of the files; reason:
" + e.Message);
return;
}
}
CodeAccessPermission.RevertAssert();
// We can't call a COM event from a thread other than the one on
// which the sinking occurred, or we'll generate an obscure
// exception. So set a timer in the main thread and force this
// event to occur elsewhere.
StartTimer();
btnRemove.Enabled = false;
}
Figure 2 Page_Load Event Handler private void Page_Load(object sender, System.EventArgs e)
{
HttpPostedFile hpf;
// Assume the user is POSTing. If not, reject attempt to connect.
if (!Request.HttpMethod.Equals("POST"))
{
Response.StatusCode = 405; // 405 == Method Not Allowed
Response.End();
}
for (int j = 0; j < Request.Files.Count; j++)
{
hpf = Request.Files.Get(j);
hpf.SaveAs("C:\\temp\\" +
hpf.FileName.Substring(hpf.FileName.LastIndexOf('\\') + 1));
}
Response.StatusCode = 200;
Response.End();
}
Figure 4 Defining the Permission Set .gif) Figure 5 Create New Permission Set .gif) Figure 8 LocalIntranet_Zone Code Group .gif) Figure 12 Onload Event Handler <HTML>
<HEAD>
<SCRIPT>
function load()
{
dotNetObj1.FileUploadUrl = "ftp://www.server.com/ServerFileUpload/
UploadFile.aspx";
}
</SCRIPT>
</HEAD>
<BODY onload="load();">
<OBJECT id="dotNetObj1" ...>
</OBJECT>
</BODY>
|