저는 일반적으로 .NET이나 C# 또는 그와 관련해 Microsoft 서버의 어떤 것도 작동하지 않습니다. 저는 보통 LINUX LAMP 개발자입니다. 그러니 나와 함께 절을하십시오. 기본적으로ASP.NET, C#, IIS, MIME 유형, 파일 업로드 조건
,
다음 코드를 제외하고, 완벽하게 작동한다, 그것은 업로드하지 않습니다 ... 나는 웹 사이트에 파일 업로드 웹 양식을 가지고 있고 그것은 특정 형식 (또는 MIME 타입)을 채택 할 필요가 .DOCX 파일을 서버에 저장하십시오! 그게 작동하지 않는 유일한 파일 형식입니다 ... 나는 코드의 모든 라인을 두 번 체크하고 심지어 .DOCX MIME 타입이 계승되었는지 확인하기 위해 IIS 관리자에 들어갔다. 그리고 그들은 ...
.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