Display uploading progress bar
Hi,
I want to show uploading process at the time of file uploading on web server, i have use following code :
private void btnVideoupload_Click(object sender,
RoutedEventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Multiselect = false;
dlg.Filter = "Video Files (*.mp4)|*.mp4|Video Files (*.mpeg)|*.mpeg| Video Files (*.wmv)|*.wmv";
dlg.FilterIndex = 1;
bool? retval = dlg.ShowDialog();
if (retval != null && retval == true)
{
txtVideoPath.Text = dlg.File.Name; strmVideo1 = dlg.File.OpenRead();
UploadVideo(dlg.File.Name, dlg.File.OpenRead());
}
else
{
txtVideoPath.Text = "No file selected...";
}
}
private void UploadVideo(string fileName, Stream data)
{
if (strImagePath != "")
{
UriBuilder ub = new UriBuilder("http://www.demosite.com/ Video_Upload.ashx");
ub.Query = string.Format("filename={0}", fileName);
WebClient c = new WebClient();
c.OpenWriteCompleted += (sender, e) =>
{
PushVideo(data, e.Result, fileName);
e.Result.Close();
data.Close();
};
c.OpenWriteAsync(ub.Uri);
}
}
private void PushVideo(Stream input,
Stream output,
String strFileName)
{
byte[] buffer = new byte[input.Length];
int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) != 0)
{
output.Write(buffer, 0, bytesRead);
}
}