ASP.NET,C#,IIS,MIME类型,文件上传条件
发布时间:2020-12-16 04:05:24 所属栏目:asp.Net 来源:网络整理
导读:我在网站上有一个文件上传网页表单,它只需要接受某些格式(或MIME类型)… 以下代码完美地工作,除了,它不会将.DOCX文件上传到服务器!这是唯一不起作用的文件类型…我已经仔细检查了每一行代码,甚至已经进入IIS管理器以确保继承了.DOCX 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 编辑: || FileUpload1.PostedFile.FileName.ToLower().Substring(FileUpload1.PostedFile.FileName.Length - 4) == "docx" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 什么是AsyncManager.OutstandingOperations
- asp.net – 对数据绑定集合或对象列表时对gridview进行排序
- 实体框架 – WebApi OData:$filter’any’或’all’查询不
- asp.net-mvc – Asp.net MVC 1和Asp.net MVC 2之间的区别
- asp.net-mvc-3 – MVC3不显眼的验证在IE中不起作用
- asp.net – 如何获取当前登录用户的角色列表
- 在ASP.NET 5中,如何在中间件中获取所选路由?
- asp.net – 我的URL中的这些随机字符是什么?它们是如何实现
- 在ASP.Net的URL中检索锚点链接
- msbuild – 通过TFS 2015部署ASP.NET 5(vNext)
推荐文章
站长推荐
- razor – 没有布局参考的ASP.NET默认MVC4应用程序
- asp.net-core – ABP框架中的集成Windows身份验证
- asp.net-web-api – 如何从ASP.net 5 web api返回
- 通过HTTPS在ASP.NET中安全的会话cookie
- asp.net-mvc – XmlMediaTypeFormatter无法编写O
- asp.net-mvc-3 – DropDownListFor – 不选择“S
- asp.net-mvc-3 – ASP.NET MVC3从https重定向到h
- asp.net – HTTP错误403 – 禁止
- ASP.NET Core 2.0 全局配置项
- 验证 – ASP.NET Web API是否支持IValidatableOb
热点阅读