zoukankan      html  css  js  c++  java
  • 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();
                }

            }
     

  • 相关阅读:
    前端总结--性能优化
    Vue面试中,经常会被问到的面试题/Vue知识点整理
    面试怎么样?才会容易进入到心仪公司了
    Vuex,从入门到入门
    当面试官问你“有什么缺点”时,应如何体面的回答?
    Linux下文件搜索、查找、查看命令
    线程池运行机制
    win10右键很慢
    Linux 安装 Tomcat7
    Tomcat / Nginx 跨域
  • 原文地址:https://www.cnblogs.com/wenjie/p/1389428.html
Copyright © 2011-2022 走看看