Silverlight文件下载完美版

Silverlight文件下载完美版,第1张

概述页面:hlink.NavigateUri = new Uri(ServiceHelper.BaseUrl + ServicePath.DownFilePath + "?fileName="+((Sys_AttachmentLibraryModel)selDownFile.SelectedItem).FileUrl.ToString()); 服务端:DownLoadFileHandler.ashx

页面: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文件下载完美版所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1071593.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存