void grdHistory_RowCommand(object sender, GridViewCommandEventArgs e) { int archiveID = Convert.ToInt32(e.CommandArgument); switch (e.CommandName) { case "restore": //SharedFile.RestoreHistoryFile(archiveID, this.upLoadPath, this.historyPath); SharedFilesHelper.RestoreHistoryFile(archiveID, fileSystem, virtualSourcePath, virtualHistoryPath); WebUtils.SetupRedirect(this, Request.RawUrl); break; case "deletehx": SharedFilesHelper.DeleteHistoryFile(archiveID, fileSystem, virtualHistoryPath); SharedFile.DeleteHistory(archiveID); WebUtils.SetupRedirect(this, Request.RawUrl); break; case "download": SharedFileHistory historyFile = SharedFile.GetHistoryFile(archiveID); if (historyFile != null) { string fileType = Path.GetExtension(historyFile.FriendlyName).Replace(".", string.Empty); if (string.Equals(fileType, "pdf", StringComparison.InvariantCultureIgnoreCase)) { //this will display the pdf right in the browser Page.Response.AddHeader("Content-Disposition", "filename=" + historyFile.FriendlyName); } else { // other files just use file save dialog Page.Response.AddHeader("Content-Disposition", "attachment; filename=" + historyFile.FriendlyName); } //Page.Response.AddHeader("Content-Length", documentFile.DocumentImage.LongLength.ToString()); Page.Response.ContentType = "application/" + fileType; Page.Response.Buffer = false; Page.Response.BufferOutput = false; //Response.TransmitFile(historyPath + historyFile.ServerFileName); //Response.End(); using (System.IO.Stream stream = fileSystem.GetAsStream(virtualHistoryPath + historyFile.ServerFileName)) { stream.CopyTo(Page.Response.OutputStream); } try { Page.Response.End(); } catch (System.Threading.ThreadAbortException) { } } break; } }
void grdHistory_RowCommand(object sender, GridViewCommandEventArgs e) { if (!(e.CommandArgument is Int32)) { return; } int archiveID = Convert.ToInt32(e.CommandArgument); switch (e.CommandName) { case "restore": SharedFile.RestoreHistoryFile(archiveID, this.upLoadPath, this.historyPath); WebUtils.SetupRedirect(this, Request.RawUrl); break; case "download": SharedFileHistory historyFile = SharedFile.GetHistoryFile(archiveID); if (historyFile != null) { string fileType = Path.GetExtension(historyFile.FriendlyName).Replace(".", string.Empty); if (string.Equals(fileType, "pdf", StringComparison.InvariantCultureIgnoreCase)) { //this will display the pdf right in the browser Page.Response.AddHeader("Content-Disposition", "filename=" + historyFile.FriendlyName); } else { // other files just use file save dialog Page.Response.AddHeader("Content-Disposition", "attachment; filename=" + historyFile.FriendlyName); } //Page.Response.AddHeader("Content-Length", documentFile.DocumentImage.LongLength.ToString()); Page.Response.ContentType = "application/" + fileType; Page.Response.Buffer = false; Page.Response.BufferOutput = false; Response.TransmitFile(historyPath + historyFile.ServerFileName); Response.End(); } break; } }