Here are a few examples that show how to write a stream to a specified resource using the WebClient class :
Using WebClient.OpenWrite :
using (var client = new WebClient()) { var fileContent = System.IO.File.ReadAllBytes(fileName); using (var postStream = client.OpenWrite(endpointUrl)) { postStream.Write(fileContent, 0, fileContent.Length); } }
Using WebClient.OpenWriteAsync :
using (var client = new WebClient()) { client.OpenWriteCompleted += (sender, e) => { var fileContent = System.IO.File.ReadAllBytes(fileName); using (var postStream = e.Result) { postStream.Write(fileContent, 0, fileContent.Length); } }; client.OpenWriteAsync(new Uri(endpointUrl)); }
source share