General discussion

Locked

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.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Valeri Makarov In reply to File Upload using C#

string fileName = "";
FileInfo fi = new FileInfo(fileName);
try
{
Uri serUri = new Uri(txtServer.Text + fi.Name);
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(serUri);
System.Net.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);
}
sw.Close();
fs.Close();
myStream.Close();
success = total == fileSize;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
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

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums