WebClient Open Write using C#

Sample for WebClient Open Write using C#.

using System;
using System.IO;
using System.Net;
public class myTest
{

WebClient webClient = new WebClient();
string data = "upload data using webclient.";
Stream stream = webClient .OpenWrite(url);
StreamWriter sw = new StreamWriter(stream);
sw.WriteLine(data);
sw.Close();
stream.Close();
}

1 comment:

Unknown said...

I have same problem webclient.openwrite is not writing data to file. It giving an error that webexception remote server returned an error 406 not acceptable when I close connection and it not write data to file. When I call flush method for writing, it not write data to file and autoflush is also not working. Then what can I do to write data to file on server. Please help me for this.