dheeraj_bhat
Я не уверен, в чем проблема, но это работает для меня в обоих случаях....Дайте мне знать, если это сработает
if (File.Exists(filepath)) {
string filename = Path.GetFileName(filepath);
Response.Clear();
Response.ContentType = GetMimeTypeByFileName(filename);
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
Response.AddHeader("Content-Length", mfile.Length.ToString());
Response.TransmitFile(filepath);
Response.End();
}
Функция GetMimeTypeByFileName (имя файла) находится ниже
public string GetMimeTypeByFileName(string sFileName)
{
string sMime = "application/octet-stream";
string sExtension = System.IO.Path.GetExtension(sFileName);
if (!string.IsNullOrEmpty(sExtension)) {
sExtension = sExtension.Replace(".", "");
sExtension = sExtension.ToLower();
if (sExtension == "xls" || sExtension == "xlsx") {
sMime = "application/ms-excel";
} else if (sExtension == "pdf") {
sMime = "application/pdf";
} else if (sExtension == "doc" || sExtension == "docx") {
sMime = "application/msword";
} else if (sExtension == "ppt" || sExtension == "pptx") {
sMime = "application/ms-powerpoint";
} else if (sExtension == "rtf") {
sMime = "application/rtf";
} else if (sExtension == "zip") {
sMime = "application/zip";
} else if (sExtension == "mp3") {
sMime = "audio/mpeg";
} else if (sExtension == "bmp") {
sMime = "image/bmp";
} else if (sExtension == "gif") {
sMime = "image/gif";
} else if (sExtension == "jpg" || sExtension == "jpeg") {
sMime = "image/jpeg";
} else if (sExtension == "png") {
sMime = "image/png";
} else if (sExtension == "tiff" || sExtension == "tif") {
sMime = "image/tiff";
} else if (sExtension == "txt") {
sMime = "text/plain";
}
}
return sMime;
}