我通常不使用.NET或C#或Microsoft服務器上的任何事情。我通常是LINUX LAMP Developer,所以請和我一起裸照。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.";
}
我唯一能想到的就是IIS沒有爲DOCX配置的MIME類型(不是它應該真的需要上載,但它可能有軸承),您是否檢查過一個擴展的設置? – dougajmcdonald
查看[Fiddler](http://www.fiddler2.com/fiddler2/),這可能會幫助您確定究竟是什麼MIME字符串被推上電線(儘管我認爲它應該是「application/msword」你有。)) –
當你上傳.docx文件時,FileUpload1.PostedFile.ContentType的值是多少?或者它沒有那麼遠? – Town