• 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();
                }

            }
     

  • 相关阅读:
    Linux 一块网卡配置多个IP的方法
    Nginx详解篇
    Nginx故障排错及一个网站小实例
    Nginx web 服务器 安装篇
    一些看起来比较专业的工具
    Linux 下软件的安装方法
    Mysq登陆后执行命令提示You must SET PASSWORD before executing this statement
    Linux-Centos 虚拟机安装
    Mysql的多种安装方法———rpm安装
    etcd安装和简单使用
  • 原文地址:https://www.cnblogs.com/wenjie/p/1389428.html
Copyright © 2020-2023  润新知