on the server side, I’ve got these:
ASPX:
<form id="form1" runat="server" enctype="multipart/form-data">
<input type="file" id="myFile" name="myFile" />
<asp:Button runat="server" ID="btnUpload" OnClick="btnUploadClick" Text="Upload" />
</form>
CS:
protected void btnUploadClick(object sender, EventArgs e)
{
HttpPostedFile file = Request.Files["myFile"];
if (file != null && file.ContentLength > 0)
{
string fname = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath(Path.Combine("~/Files/", fname)));
}
}
Client Side app: it uses WebClient but I didn’t think this was needed for any solution since webclient is pretty simple and straight forward. Anyways, here’s the code
private void btnStart_Click(object sender, RoutedEventArgs e)
{
Uri uploadAddress = new Uri("http://localhost/WebUpload/default.aspx");
WebClient wc = new WebClient();
wc.UploadProgressChanged += new UploadProgressChangedEventHandler(wc_UploadProgressChanged);
wc.UploadFileCompleted += new UploadFileCompletedEventHandler(wc_UploadFileCompleted);
wc.Credentials = CredentialCache.DefaultCredentials;
wc.UploadFile(uploadAddress, "POST", m_filename);
}
void wc_UploadFileCompleted(object sender, UploadFileCompletedEventArgs e)
{
if (e.Error != null)
txtProgress.Content = e.Error.Message;
else
txtProgress.Content = "Completed";
}
void wc_UploadProgressChanged(object sender, UploadProgressChangedEventArgs e)
{
txtProgress.Content = String.Format("{0}% completed",
e.ProgressPercentage);
}
as for the client app: it’s a simple webclient using uploadfileasync via HTTP POST to the aspx page.
Question: files gets saved normally using the aspx page but for the client app, the file gets uploaded and but doesn’t get saved on the folder. What might be happening? I’m pretty sure this is a server side problem.
Update: added the client side code. The client app works on another (but asp classic) server so I’m doubting that the client is the one that needs fixing.
Reposting my comment since Jan never posted an answer.
Thanks to Jan for pointing me to the right direction. The file receiving code should have been in the page_load, that was careless of me. Another problem was the string name of the index of the file (Request.Files[“myFile”]) which should be of the same id as the input control in the aspx page.