/// <summary> /// locate versions of what were once physical files utilizing form/DocTypeName/VersionNumber/*.* /// from archives of what was once seen & now compressed as cab in the document database. /// This allows older documents in the field to request resources that deployed a long time ago /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { // ensure the latest content has been processed & imported ImporterController.ImportDocModelsRunOnce(); //TODO:move ~/web.config ManifestRewrite_Integrated & ManifestRewrite_Classic structures to ~/form/web.config so there is no need for this manifest.xsf httphandler switching logic section to if (context.Request.Url.ToString().ToLower().EndsWith("manifest.xsf")) { new ManifestRewriter().ProcessRequest(context); } else { string filename; using (MemoryStream _MemoryStream = TemplateController.Instance.OpenRead(context, out filename)) { context.Response.DisableKernelCache(); context.Response.Clear(); context.Response.ClearContent(); context.Response.ClearHeaders(); _MemoryStream.CopyTo(context.Response.OutputStream); context.Response.ContentType = MimeExtensionHelper.GetMimeType(filename); context.Response.AddHeader("content-disposition", "attachment; filename=\"" + filename + "\";"); } } }
/// <summary> /// locate versions of what were once physical files utilizing form/DocTypeName/VersionNumber/*.* /// from archives of what was once seen & now compressed as cab in the document database. /// This allows older documents in the field to request resources that deployed a long time ago /// </summary> /// <param name="context"></param> public virtual void ProcessRequest(HttpContext context) { TemplateFileInfo templatefileinfo; using (MemoryStream _MemoryStream = TemplateController.Instance.OpenRead(context, out templatefileinfo)) { context.Response.DisableKernelCache(); context.Response.Clear(); context.Response.ClearContent(); context.Response.ClearHeaders(); _MemoryStream.CopyTo(context.Response.OutputStream); context.Response.ContentType = MimeExtensionHelper.GetMimeType(templatefileinfo.FileName); context.Response.AddHeader("content-disposition", "attachment; filename=\"" + templatefileinfo.FileName + "\";"); } }
protected FileResult DownloadFileAttachment(string fileName, string fileNameHalfPath) { string fileDownloadName = null; var tempF = fileNameHalfPath.Split('\\'); int countF = tempF.Length; fileDownloadName = tempF[countF - 1]; fileNameHalfPath = fileNameHalfPath.Replace(@"\\", @"\"); fileNameHalfPath = fileNameHalfPath.Remove(0, 1); string prePathMain = null; string prePathTemp = null; string fileNameServerFullPath = null; prePathMain = itemRepo.FindBySettingCd(CommonConstant.SYS_FILE_LOC_MAIN_FOLDER); prePathTemp = itemRepo.FindBySettingCd(CommonConstant.SYS_FILE_LOC_TEMP_FOLDER); string mainFullPath = Path.Combine(prePathMain, fileNameHalfPath); string tempFullPath = Path.Combine(prePathTemp, fileNameHalfPath); if (System.IO.File.Exists(mainFullPath)) { fileNameServerFullPath = mainFullPath; } else { fileNameServerFullPath = tempFullPath; } if (!string.IsNullOrEmpty(fileName)) { fileDownloadName = fileName; } Response.AddHeader("Set-Cookie", "fileDownload=true; path=/"); return(File(fileNameServerFullPath, MimeExtensionHelper.GetMimeType(fileDownloadName), fileDownloadName)); }
//protected void SendToClientBrowser(string fileName, byte[] hasil) //{ // Response.Clear(); // //Response.ContentType = result.MimeType; // Response.Cache.SetCacheability(HttpCacheability.Private); // Response.Expires = -1; // Response.Buffer = true; // Response.ContentType = "application/octet-stream"; // Response.AddHeader("Content-Length", Convert.ToString(hasil.Length)); // Response.AddHeader("Content-Disposition", string.Format("{0};FileName=\"{1}\"", "attachment", fileName)); // Response.AddHeader("Set-Cookie", "fileDownload=true; path=/"); // Response.BinaryWrite(hasil); // Response.End(); //} // Summary: // Handle Download File Request // // Parameters: // fileName : the filename to be download // paths : list path will be search the file // fileDownloadName : the filename to be send to browser protected FileResult DownloadFile(string fileName, IList <string> paths, string fileDownloadName) { string fileNameServerFullPath = null; foreach (string path in paths) { fileNameServerFullPath = Path.Combine(path, fileName); if (System.IO.File.Exists(fileNameServerFullPath)) { break; } } if (string.IsNullOrEmpty(fileDownloadName)) { fileDownloadName = fileName; } Response.AddHeader("Set-Cookie", "fileDownload=true; path=/"); return(File(fileNameServerFullPath, MimeExtensionHelper.GetMimeType(fileDownloadName), fileDownloadName));/*MimeMapping.GetMimeMapping(fileName)*/ }