download doc file from server in silverlight
How to download doc file from server in silverlight4
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SLDeveloperPosted May 3, 2012, 9:03 AM
I am Considering you have saved your doc file on DB in bytes format & if not then save your doc file in bytes to DB
Try this :
1. Call asyncronous method of WCF to get the bytes of a file
2. Write resulted bytes to file at Client Side , you can do something like this
private void btnDownload_Click (object sender, RoutedEventArgs e)
{
try
{
DownloadFile = new SaveFileDialog();
DownloadFile.Filter = "All Files(*.*)|*.*";
DownloadFile.ShowDialog();
if (!string.IsNullOrEmpty(DownloadFile.SafeFileName))
{
proxy.DownloadFileAsync(orgfilename, DownloadFile.SafeFileName);
}
}
catch (Exception ex)
{
}
}
Download asyncronous calll to get the bytes of a file
void proxy_DownloadFileCompleted (object sender, ServiceReference1.DownloadImageCompletedEventArgs e)
{
try
{
if (e.Result.ToString() == "-200")
{
}
else if (e.Result.ToString() != null)
{
file = Convert.FromBase64String(e.Result.ToString());
if (DownloadFile.SafeFileName != null && !string.IsNullOrEmpty(DownloadFile.SafeFileName))
{
using (System.IO.Stream stream = DownloadFile.OpenFile())
{
stream.Write(file, 0, file.Length);
stream.Close();
}
}
}
else if (e.Result.ToString() != null)
{
}
}
catch (Exception ex)
{
}
}
Orignal Source of Discussion :
http://forums.silverlight.net/t/215750.aspx/1