Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is a known <a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=470465" rel="nofollow noreferrer">bug</a> in the WebClient class. It will be fixed in .NET 4.0. Until then you could use <a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx" rel="nofollow noreferrer">HttpWebRequest</a> to implement this functionality.</p> <hr> <p>UPDATE: Here's an example of using synchronous HttpWebRequest to upload a file and track the progress:</p> <pre><code>public sealed class Uploader { public const int CHUNK_SIZE = 1024; // 1 KB public void Upload(string url, string filename, Stream streamToUpload, Action&lt;int&gt; progress) { var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; string boundary = string.Format("---------------------{0}", DateTime.Now.Ticks.ToString("x")); request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary); request.KeepAlive = true; using (var requestStream = request.GetRequestStream()) { var header = string.Format("--{0}\r\nContent-Disposition: form-data; name=\"file\"; filename=\"{1}\"\r\nContent-Type: application/octet-stream\r\n\r\n", boundary, filename); var headerBytes = Encoding.ASCII.GetBytes(header); requestStream.Write(headerBytes, 0, headerBytes.Length); byte[] buffer = new byte[CHUNK_SIZE]; int bytesRead; long total = streamToUpload.Length; long totalBytesRead = 0; while ((bytesRead = streamToUpload.Read(buffer, 0, buffer.Length)) &gt; 0) { totalBytesRead += bytesRead; progress((int)(100 * totalBytesRead / total)); byte[] actual = new byte[bytesRead]; Buffer.BlockCopy(buffer, 0, actual, 0, bytesRead); requestStream.Write(actual, 0, actual.Length); } } using (var response = request.GetResponse()) { } } } class Program { static void Main(string[] args) { var url = "http://localhost:2141/Default.aspx"; var filename = "1.dat"; var uploader = new Uploader(); using (var fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { uploader.Upload(url, filename, fileStream, progress =&gt; Console.WriteLine("{0}% of \"{1}\" uploaded to {2}", progress, filename, url)); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload