2012-01-16 9 views

risposta

1

Dovresti essere in grado di utilizzare i metodi WebClient.OpenWrite e OpenWriteAsync per inviare uno stream al tuo server.

Se si utilizza la versione successiva, effettuare la sottoscrizione a OpenWriteCompleted e utilizzare e.Result come stream su CopyTo.

2

Ecco alcuni esempi che illustrano come scrivere flusso alla risorsa specificata utilizzando WebClient class:

Utilizzando 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); 
    } 
} 

Utilizzando 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)); 
} 
Problemi correlati