VisualStudioFeeds

All Visual Studio blogs in one place

AddThis Social Bookmark Button
        void UploadStream(string fileName, Stream stream, string uri, string authorizationHeader)         {             var webRequest = WebRequest.Create(uri);             var boundary = DateTime.Now.Ticks.ToString();             webRequest.ContentType = "multipart/form-data; boundary=" + boundary;             webRequest.Method = HttpMethod.Post;             webRequest.Headers["Authorization"] = authorizationHeader;             var memoryStream = new MemoryStream();             stream.CopyTo(memoryStream);             var byteArray = memoryStream.ToArray();             var postData = new MemoryStream();             const string newLine = "\r\n";             var sw = new StreamWriter(postData);             sw.Write("--" + boundary + newLine);             sw.Write("Content-Disposition: form-data;name=\"{0}\";filename=\"{1}\"{2}", "upload", fileName, newLine + newLine);             sw.Flush();             postData.Write(byteArray, 0, byteArray.Length);             sw.Write(newLine);             sw.Write("--{0}--{1}", boundary, newLine);             sw.Flush();             webRequest.ContentLength = postData.Length;             using (var requestStream = webRequest.GetRequestStream()) postData.WriteTo(requestStream);             postData.Close();         }

Search

Subscribe

Enter your email address:

Delivered by FeedBurner

Increase your website traffic with Attracta.com

Contact

Email:
Subject:
Message:
Anti-spam: How many eyes has a typical person?

Follow us on FB

Home : Blog List : .Nettuce : Multipart form using WebRequest