
网上搜索的解决方案,要么是通过silverlight客户端来下载,要么通过asp.net来下载,不一而足,各有优缺点。这里不评价各种优缺点,只记述了自己实现的结果。这里需要下载的文件是存放在服务器上的,并考虑到了虚拟目录的。一些动态生成的文件,也可以以此处理。
asp.net端的代码,短短的,没有几行:
public voID ProcessRequest(httpContext context) { string filename = context.Request.queryString["filename"]; string physical_file_name = context.Server.MapPath(filename); fileInfo fi = new fileInfo(physical_file_name); //context.Response.Output.Writeline("物理文件名:" + physical_file_name); context.Response.Clear(); context.Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 context.response.addheader("Content-disposition","attachment; filename=" + fi.name); context.Response.Writefile(physical_file_name); } silverlight端的处理:
NavigationService.Navigate(url);总结
以上是内存溢出为你收集整理的silverlight文件下载方法全部内容,希望文章能够帮你解决silverlight文件下载方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)