Web Development

General discussion


File Upload using C#

By medasatheesh ·
Hi I have to upload a file to a webserver from my desktop. My client side application should be a windows application developed in C#.
Please give me solution how to do it?

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by Valeri Makarov In reply to File Upload using C#

string fileName = "";
FileInfo fi = new FileInfo(fileName);
Uri serUri = new Uri(txtServer.Text + fi.Name);
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(serUri);
wr.Method = "PUT";
long fileSize = fi.Length;
System.IO.Stream myStream = wr.GetRequestStream();
System.IO.BinaryWriter sr = new System.IO.BinaryWriter(myStream);
System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open);
System.IO.BinaryReader sw = new System.IO.BinaryReader(fs);
int rd = 0;
long total = 0;
int bufSize = 1024;
byte []buf = new byte[bufSize];
while((rd = sw.Read(buf, 0, bufSize)) != 0)
total += rd;
sr.Write(buf, 0, rd);
success = total == fileSize;
catch(Exception ex)
success = false;
MessageBox.Show(this, "Upload is "+success.ToString());

Collapse -

by uwadekar In reply to File Upload using C#

I have also same problem can u give me solution when u get it.
Thanks in advance

Related Discussions

Related Forums