Home > ASP.NET > Upload file from Windows application to asp.net web server

Upload file from Windows application to asp.net web server

Its simple with the WebClient class. Just include this code inside the Windows client application.

  System.Net.WebClient Client = new System.Net.WebClient();
Client.Headers.Add(“Content-Type”, “binary/octet-stream”);
byte[] result = Client.UploadFile(“http://localhost:57361/Default.aspx”, “POST”, file);
String s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);

MessageBox.Show(s);

The Default.aspx page as receiver look like this

  protected void Page_Load(object sender, EventArgs e)
{

string fname = Request.Files[0].FileName;

Request.Files[0].SaveAs(Server.MapPath(Path.Combine(“~/Images/”, fname)));

Response.Write(“Uploaded”);
Response.End();

}

You can download the sample from here

https://skydrive.live.com/redir?resid=6DAACA1E5AB7FFE1!886&authkey=!AAIgGN9RfSK72Kg

happy coding 🙂

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: