zoukankan      html  css  js  c++  java
  • GetContentType

    文件下载

    文件下载

                    var fileDownloadName = file.FlieName + System.IO.Path.GetExtension(filePath);
                    var mimeType = GetContentType(System.IO.Path.GetExtension(filePath)); ;
                    return File(FileStream(filePath), mimeType, fileDownloadName);
            public Stream FileStream(string path)
            {
                using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
                {
                    WebClient webClient = new WebClient();
    
                    var obj = webClient.OpenRead(path);
                    return obj;
                }
            }
            private string GetContentType(string fileExt)
            {
                switch (fileExt)
                {
                    case ".doc":
                        return "application/msword";
                    case "docx":
                        return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                    case ".rtf":
                        return "application/rtf";
                    case ".xls":
                        return "application/vnd.ms-excel";
                    case ".xlsx":
                        return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                    case ".ppt":
                        return "application/vnd.ms-powerpoint";
                    case ".pptx":
                        return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                    case ".pdf":
                        return "application/pdf";
                    case ".swf":
                        return "application/x-shockwave-flash";
                    case ".rar":
                        return "application/octet-stream";
                    case ".zip":
                        return "application/x-zip-compressed";
                    case ".mp3":
                        return "audio/mpeg";
                    case ".gif":
                        return "image/gif";
                    case ".png":
                        return "image/png";
                    case ".jpeg":
                        return "image/jpeg";
                    case ".jpg":
                        return "image/jpeg";
                    case ".jpe":
                        return "image/jpeg";
                    case ".txt":
                        return "text/plain";
                    case ".bmp":
                        return "image/jpeg";
                    case ".exe":
                        return "application/octet-stream";
    
                    default:
                        return "application/octet-stream";
    
                }
    
            }
  • 相关阅读:
    Linux 下安装nodejs
    Linux 下安装JDK
    ubuntu 把软件源修改为国内源
    vi/vim 命令使用详解
    不同浏览器css引入外部字体的方式
    npx 命令介绍
    ICloud没有密码怎么注销?
    装修后才知道的79件事
    天翼宽带政企网关B2-1P 如何获得超级管理员账号?
    家庭治疗偏头痛
  • 原文地址:https://www.cnblogs.com/wangyinlon/p/10723796.html
Copyright © 2011-2022 走看看