Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,
I make a datagrid that contron a progress bar and i want to access progress bar when i upload files and other content and run the progress bar on every file uploading. I make a multifile uploading system. Please help me i give code below.
<pre lang="c#"> <data:DataGrid Name="FileList" LoadingRow="DataGrid_LoadingRow" Margin="0,0,6,6" AutoGenerateColumns="False" Loaded="FileList_Loaded">
<data:DataGrid.Columns>
<data:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="File Name" Width="150" Binding="{Binding Name}"/>
<data:DataGridTextColumn CanUserReorder="True" CanUserResize="True" CanUserSort="True" Header="File Size" Width="80" Binding="{Binding Length}" />
<data:DataGridTemplateColumn Header="Status">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<ProgressBar x:Name="progressBar2" Minimum="0" Maximum="{Binding Length}" Visibility="Visible" IsEnabled="False" Width="50" Height="15"/>
</StackPanel>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
<data:DataGridTemplateColumn>
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<Button Name="btnremove" Content="Remove" Click="btnremove_Click"></Button>
</StackPanel>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>

<!--<ProgressBar x:Name="progressBar" Minimum="0" Maximum="{Binding FileLength}" Value="{Binding BytesUploaded}" Visibility="Collapsed" />-->
</data:DataGrid>

//////////////////////////////////////////////////////////
private void button1_Click(object sender, RoutedEventArgs e)
{
progressBar1.Value = 0;
if (listBox1.SelectedIndex == -1)
{
MessageBox.Show("Please Select Sku No");
return;
}
if (listBox2.SelectedIndex == -1)
{
MessageBox.Show("Please Select PhotoGrapher Name");
return;
}
long PId = ((skuUploading.GetDataSerivces.login)(((System.Windows.Controls.Primitives.Selector)(listBox2)).SelectedItem)).RefferenceID;
long sku = ((skuUploading.GetDataSerivces.trackWork)(((System.Windows.Controls.Primitives.Selector)(listBox1)).SelectedItem)).JabongBarCode;
string data = string.Empty;
foreach (var file in fileColl)
{
using (System.IO.Stream fileStream = GetFileData(file.OpenRead()))
{
StreamResourceInfo oStreamResource = new StreamResourceInfo(fileStream, null);
byte[] array = new byte[oStreamResource.Stream.Length];
oStreamResource.Stream.Read(array, 0, (int)oStreamResource.Stream.Length);
data = Convert.ToBase64String(array);
WebClient oWebClient = new WebClient();

string fileName = Guid.NewGuid().ToString().Replace("-", "") + file.Extension;
oWebClient.UploadStringAsync(new Uri("http://localhost:51982/FileUpload.ashx?file=" + fileName + "&sku=" + sku + "&pid=" + PId), null, data, fileName);
oWebClient.UploadProgressChanged += new UploadProgressChangedEventHandler(oWebClient_UploadtxtProgressChanged);
// oWebClient.UploadStringCompleted += new UploadStringCompletedEventHandler(oWebClient_UploadStringCompleted);
TotalFileToUpload += 1;
data = string.Empty;
//var ctl = (FileList.Columns[3]) as ProgressBar;
//var ctl = Fi as ProgressBar;
//if(ctl!=null)
//{
// var pname = (ProgressBar)ctl.DataContext;

//}
}
}
}
void oWebClient_UploadtxtProgressChanged(object sender, UploadProgressChangedEventArgs e)
{

TotalFileUploaded += 1;
txtProgress.Text = string.Empty;
txtProgress.Text = !string.IsNullOrEmpty(txtProgress.Text) ? (int.Parse(txtProgress.Text) + e.BytesSent).ToString() : e.BytesSent.ToString();
//((ProgressBar)(FileList.CurrentColumn.GetCellContent(TotalFileUploaded))).IsEnabled = true;
//((ProgressBar)(FileList.CurrentColumn.GetCellContent(TotalFileUploaded))).Value = e.BytesSent;
DataGridRow drw=new DataGridRow ();
drw.DataContext="progressBar2";
<b>ProgressBar pg = ((ProgressBar)(FileList.Columns[2].GetCellContent(totalfileuploaded).FindName("progressBar2")));
progressBar1.Value = e.BytesSent;</b>
if (TotalFileUploaded == TotalFileToUpload)
txtProgress.Text = TotalFileUploaded + " files uploaded successfully (" + txtProgress.Text + " bytes sent )";
fileColl.Clear();
}
</pre>
plz help me
Posted
Updated 12-Feb-12 23:38pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900