开发者

Downloading Files in Silverlight 3

开发者 https://www.devze.com 2023-01-15 00:45 出处:网络
I have a data grid of strings which are the names of files on a remote web server. So my question is, when the user clicks on a row in the datagrid, a corresponding file should then be downloaded by

I have a data grid of strings which are the names of files on a remote web server.

So my question is, when the user clicks on a row in the datagrid, a corresponding file should then be downloaded by the web browser. The same way you normally browse to a website and click on a fil开发者_如何学Ce link which then opens in the browser and begins to download.

Looked for sample codes on MSDN but i couldn't find anything that does this.

Edit: Perhaps I need to clarify. I do not want to download the file into the Silverlight app. I want the user to download the file to their local machine wherever they choose.


you can try something on these lines

WebClient webClient = new WebClient(); webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged); webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted); webClient.OpenReadAsync(new Uri("....", UriKind.Relative));

for more details refer this


This did the trick.

Just need to make sure that popups not disabled in the browser though but that's okay for me:

Uri downloadLink = new Uri("http://www.google.com/intl/en_com/images/srpr/logo1w.png", UriKind.Absolute);
// try to download the file via browser
System.Windows.Browser.HtmlPage.Window.Navigate(downloadLink, "_blank", "height=300,width=600,top=100,left=100");
0

精彩评论

暂无评论...
验证码 换一张
取 消