Sunday, 18 August 2013

Upload file WebClient with Taskbar progressbar in C# with WindowsAPICodePack?

Upload file WebClient with Taskbar progressbar in C# with WindowsAPICodePack?

I have an error. This is the code:
// Create response variable.
string response = "";
string dir = "C:\file.png";
// Upload file.
using (WebClient client = new WebClient())
{
// Show the percentage.
client.UploadProgressChanged += (s, e) =>
{
taskbar.SetProgressValue(e.ProgressPercentage,100);
};
Uri url = new Uri("http://www.myweb.com/upload.php");
response =
client.Encoding.GetString(client.UploadValuesAsync(url, new
NameValueCollection() { { "name",
System.IO.Path.GetFileName(dir) }, { "image", "data:" +
"multipart/form-data" + ";base64," +
Convert.ToBase64String(System.IO.File.ReadAllBytes(dir)) }
}));
}
The error was in:
response = client.Encoding.GetString(client.UploadValuesAsync(url, new
NameValueCollection() { { "name", System.IO.Path.GetFileName(dir) }, {
"image", "data:" + "multipart/form-data" + ";base64," +
Convert.ToBase64String(System.IO.File.ReadAllBytes(dir)) } }));
The error: "Can't convert 'void' into 'byte[]'"

No comments:

Post a Comment