yo no suelen trabajar en .NET o C#, o cualquier cosa en un servidor de Microsoft para el caso. Soy desarrollador de LINUX LAMP por lo general, así que, por favor, desnudo conmigo.ASP.NET, C#, IIS, TIPOS MIME, carga de archivos de CONDICIONAL
Básicamente, tengo un formulario web de subida de archivos en el sitio web y tiene que aceptar ciertos formatos (o tipos MIME) ...
El siguiente código está funcionando perfectamente, excepto, al no carga .DOCX archivos al servidor! Ese es el único tipo de archivo que no funciona ... He comprobado dos veces cada línea de código e incluso he llegado al administrador de IIS para asegurar que los tipos .DOCX MIME se heredaron, y que fueron ...
Alguien más ¿Tienes alguna idea de por qué los archivos .DOCX no se subirán al servidor como lo hacen todos los demás tipos de archivos?
fragmento de código:
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.";
}
Lo único que puedo pensar es quizás IIS no tiene un tipo de MIME configurado para DOCX (no es que lo que realmente debería necesitar para cargar, pero tal vez tiene un cojinete), ¿ha comprobado que no es una configuración para la extensión? – dougajmcdonald
Salida [Fiddler] (http://www.fiddler2.com/fiddler2/), esto podría ayudar a determinar exactamente qué cadena MIME está siendo empujado hacia arriba el cable (aunque creo que sea _should_ aplicación '/ msword' (que tienes).) –
¿Cuál es el valor de 'FileUpload1.PostedFile.ContentType' cuando cargas el .docx? ¿O no llega tan lejos? – Town