mojoportal中解决下载文件名乱码问题

  在shareFilesDownload.aspx文件添加如下方法:

 

private static string UTF_FileName(string filename)
        {
            return HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8);
        }


修改Downloadfiles方法():

 private void DownloadFile()
        {
            if (
                (CurrentPage != null)
                &&(sharedFile != null)
                )
            {
                string downloadPath = Page.Server.MapPath(WebUtils.GetApplicationRoot()
                    + "/Data/Sites/" + this.CurrentPage.SiteID.ToString() + "/SharedFiles/")
                    + sharedFile.ServerFileName;

                if (File.Exists(downloadPath))
                {
                    FileInfo fileInfo = new System.IO.FileInfo(downloadPath);
                    Page.Response.AppendHeader("Content-Length", fileInfo.Length.ToString());
                }

                string fileType = Path.GetExtension(sharedFile.FriendlyName).Replace(".", string.Empty).ToLowerInvariant();
               
                if (fileType == "pdf")
                {
                    //this will display the pdf right in the browser
                    Page.Response.AddHeader("Content-Disposition", "filename=" + UTF_FileName(sharedFile.FriendlyName));
                }
                else
                {
                    // other files just use file save dialog
                    Page.Response.AddHeader("Content-Disposition", "attachment; filename=" + UTF_FileName(sharedFile.FriendlyName));
                }

                //Page.Response.AddHeader("Content-Length", documentFile.DocumentImage.LongLength.ToString());

                Page.Response.ContentType = "application/" + fileType;
                Page.Response.Buffer = false;
                Page.Response.BufferOutput = false;
                Page.Response.TransmitFile(downloadPath);
                Page.Response.End();
            }

        }
 

转载于:https://www.cnblogs.com/wenjie/archive/2009/02/12/1389428.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值