I am trying to download a file which is generated by the code on shared folder.
File is created, when i try to download the file the download code works fine but the file is not downloading on any browser.
Download button is placed in asp.net Update Panel
here is download code
try
{
String contentType = String.Empty;
FileInfo objFileInfo = null;
this.FileMode = (DownloadFileMode)Session["FileMode"]; //DownloadFileMode.SingleFile;
FileServerPath = ConfigurationManager.AppSettings["FileServerPath"];
if (this.FileMode == DownloadFileMode.SingleFile)
{
if (Session["FileName"] != null)
{
FileName = Session["FileName"].ToString();
contentType = "application/octet-stream";
objFileInfo = new FileInfo(FileServerPath + FileName);
}
else
{
FileName = Session["SingleFile"].ToString();
contentType = "application/octet-stream";
objFileInfo = new FileInfo(FileServerPath + FileName);
}
}
else if (this.FileMode == DownloadFileMode.ZippedFile)
{
FilesList = (List<String>)Session["FilesList"];
contentType = "application/x-zip-compressed";
if (FilesList.Count == 0)
throw new Exception("No file to download");
String strFilePath = String.Empty;
String strZipPath = String.Empty;
strZipPath = FileServerPath + "file" + CurrentUserSession.UserId.ToString() + "_" + CurrentUserSession.SessionId.ToString() + "_" + DateTime.Now.ToShortDateString().Replace("/", "-") + ".zip";
DownloadFiles(strZipPath, FilesList);
objFileInfo = new FileInfo(strZipPath);
}
else
{
ScriptManager.RegisterStartupScript(this.Page, typeof(String), "MessageAlert", "alert('Invalid file mode');", true);
}
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + objFileInfo.Name);
Response.AddHeader("Content-Length", objFileInfo.Length.ToString());
Response.ContentType = contentType;
Response.TransmitFile(objFileInfo.FullName);
//Response.End();
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
catch(Exception ex)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "MessageAlert", "alert('" + ex.Message + "');", false);
}