RSS

Download CSV File in Silverlight

10 Mar

Hi…

you can download csv,excel or image file like jpg ,jpeg,bmp or any formate file from server on local system then

you just use this code and resolve your problem.

This line below find out the actual path of application

 string str = App.Current.Host.Source.AbsoluteUri;

// you can replace and get the path of specific folder and file with in it.

str = str.Replace(“ClientBin/SetMyLeads.Silverlight.UI.xap”, “Samplecsv/Sample.csv”);

 

 

 

 

 

 

 

 

 

private void sampleupload_Click(object sender, RoutedEventArgs e)
{

SaveAs();

}

public void SaveAs()
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = “csv Files|*.csv”;

bool? dialogResult = dialog.ShowDialog();

if (dialogResult != true) return;

WebClient webClient = new WebClient();
webClient.OpenReadCompleted += (s, e) =>
{
try
{
using (Stream fs = (Stream)dialog.OpenFile())
{
e.Result.CopyTo(fs);
fs.Flush();
fs.Close();
}

}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
};
string str = App.Current.Host.Source.AbsoluteUri;
str = str.Replace(“ClientBin/SetMyLeads.Silverlight.UI.xap”, “Samplecsv/Sample.csv”);

webClient.OpenReadAsync(new Uri(str), UriKind.Absolute);
}

 

Advertisements
 
Leave a comment

Posted by on March 10, 2012 in Silverlight

 

Tags: , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: