ASP.NET,C#,IIS,MIME类型,文件上传条件

我在网站上有一个文件上传网页表单,它只需要接受某些格式(或MIME类型)…

以下代码完美地工作,除了,它不会将.DOCX文件上传到服务器!这是唯一不起作用的文件类型…我已经仔细检查了每一行代码,甚至已经进入IIS管理器以确保继承了.DOCX MIME类型,它们是……

有没有人知道为什么.DOCX文件不会像其他文件类型一样上传到服务器?

代码片段:

string savePath = "D:\\HIDDEN PATH HERE";
string fileMsg;

// Before attempting to perform operations
// on the file,verify that the FileUpload 
// control contains a file.
if (FileUpload1.HasFile)
{
    // Check to see that the content type is proper and allowed.
    // DOC: application/doc,appl/text,application/vnd.msword,application/vnd.ms-word,application/winword,application/word,application/x-msw6,application/x-msword
    if (
        FileUpload1.PostedFile.ContentType == "text/rtf" ||
        FileUpload1.PostedFile.ContentType == "application/doc" ||
        FileUpload1.PostedFile.ContentType == "appl/text" ||
        FileUpload1.PostedFile.ContentType == "application/vnd.msword" ||
        FileUpload1.PostedFile.ContentType == "application/vnd.ms-word" ||
        FileUpload1.PostedFile.ContentType == "application/winword" ||
        FileUpload1.PostedFile.ContentType == "application/word" ||
        FileUpload1.PostedFile.ContentType == "application/msword" ||       
        FileUpload1.PostedFile.ContentType == "application/x-msw6" ||
        FileUpload1.PostedFile.ContentType == "application/x-msword" ||
        FileUpload1.PostedFile.ContentType == "application/pdf" ||
                        FileUpload1.PostedFile.ContentType == "application/x-pdf" ||
        FileUpload1.PostedFile.ContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" ||
        FileUpload1.PostedFile.ContentType == "application/vnd.openxmlformats-officedocument.wordprocessingml.template"
        )
    {
        // Get the name of the file to upload.
        String fileName = FileUpload1.FileName;

        // Append the name of the file to upload to the path.
        savePath += strNow + fileName;


        // Call the SaveAs method to save the 
        // uploaded file to the specified path.
        // This example does not perform all
        // the necessary error checking.               
        // If a file with the same name
        // already exists in the specified path,// the uploaded file overwrites it.
        FileUpload1.SaveAs(savePath);

        // Notify the user of the name of the file
        // was saved under.
        //fileMsg = "Your file was saved as " + fileName;
        fileMsg = "";
    }
    else
    {
        fileMsg = "Your file was not an accepted format. Please use PDF,RTF or DOC formats."; 
    }

解决方法

this answer,它指向 this page.

DOCX Mime类型:

application/vnd.openxmlformats-officedocument.wordprocessingml.document

编辑:
对不起,没有在列表中看到它.如果您想允许DOCX,为什么不检查“.docx”作为扩展名.

|| FileUpload1.PostedFile.FileName.ToLower().Substring(FileUpload1.PostedFile.FileName.Length - 4) == "docx"

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....