页面:hlink.NavigateUri = new Uri(ServiceHelper.BaseUrl + ServicePath.DownfilePath + "?filename="+((Sys_AttachmentlibraryModel)selDownfile.SelectedItem).fileUrl.ToString());
服务端:DownLoadfileHandler.ashx
using System; using System.Collections.Generic; using System.linq; using System.Web; using System.IO;public class DownLoadfileHandler : BaseService{ public overrIDe voID ProcessRequest(httpContext context) { Context = context; Result = new ActionResult(); String filename = context.Request.queryString["filename"]; //客户端保存的文件名 filename = httpUtility.UrlDecode(filename); String filePath = ConfigHelper.Uploadpath+ filename; //路径 fileInfo fileInfo = new fileInfo(filePath); if (fileInfo.Exists) { byte[] buffer = new byte[102400]; context.Response.Clear(); fileStream iStream = file.OpenRead(filePath); long dataLengthToRead = iStream.Length; //获取下载的文件总大小 context.Response.ContentType = "application/octet-stream"; context.response.addheader("Content-disposition","attachment; filename=" + httpUtility.UrlEncode(filename.Substring(filename.LastIndexOf("\")+1),System.Text.EnCoding.UTF8)); while (dataLengthToRead > 0 && context.Response.IsClIEntConnected) { int lengthRead = iStream.Read(buffer,Convert.ToInt32(102400));//'读取的大小 context.Response.OutputStream.Write(buffer,lengthRead); context.Response.Flush(); dataLengthToRead = dataLengthToRead - lengthRead; } context.Response.Close(); context.Response.End(); } // 输出结果 OutputResult(); }}总结
以上是内存溢出为你收集整理的Silverlight文件下载完美版全部内容,希望文章能够帮你解决Silverlight文件下载完美版所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)