private void EnsureNotChangedMaterial() { if (this._Content.ContentData == null) { if (this.TempPhysicalFilePath.IsNotEmpty()) { FileInfo tempFile = new FileInfo(this.TempPhysicalFilePath); if (tempFile.Exists) { this._Content.ContentData = tempFile.OpenRead().ToBytes(); } } if (this._Content.ContentData == null) { IMaterialContentPersistManager manager = MaterialContentSettings.GetConfig().PersistManager; //在数据库存储附件的模式下,这个参数其实没用 manager.DestFileInfo = new FileInfo(GetTempPhysicalFilePath(string.Empty)); this._Content.ContentData = manager.GetMaterialContent(this._Content.ContentID).ToBytes(); } } }
private void EnsureChangedImage() { if (this.SourceImageID.IsNullOrEmpty()) { this._Content.PhysicalSourceFilePath = ImagePropertyAdapter.Instance.GetPhysicalUploadImagePath(this._Content.FileName); } else { IMaterialContentPersistManager manager = MaterialContentSettings.GetConfig().PersistManager; manager.DestFileInfo = ImagePropertyAdapter.Instance.GetPhysicalUploadImagePath(this._Content.FileName); if (!File.Exists(manager.DestFileInfo.DirectoryName)) { Directory.CreateDirectory(manager.DestFileInfo.DirectoryName); } using (Stream srcContent = manager.GetMaterialContent(this.SourceImageID)) { using (FileStream fs = new FileStream(manager.DestFileInfo.ToString(), FileMode.Create, FileAccess.Write)) { srcContent.CopyTo(fs); } this._Content.PhysicalSourceFilePath = manager.DestFileInfo; } } }
public static HttpResponseMessage ProcessMaterialDownload(this MaterialModel material, string rootPathName = MaterialUploadModel.DefaultRootPathName) { material.NullCheck("material"); HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); FileInfo destFileInfo = null; if (rootPathName.IsNullOrEmpty()) { rootPathName = MaterialUploadModel.DefaultRootPathName; } if (material.Status == MaterualModelStatus.Inserted) { destFileInfo = GetTempUploadFilePath(material.ID, rootPathName, material.OriginalName); } IMaterialContentPersistManager persistManager = GetMaterialContentPersistManager(material.ID, destFileInfo); Stream stream = persistManager.GetMaterialContent(material.ID); result.Content = new StreamContent(stream); result.Content.Headers.ContentType = new MediaTypeHeaderValue(GetFileContentType(material.OriginalName)); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("Attachment") { FileName = HttpContext.Current.EncodeFileNameByBrowser(material.OriginalName) }; return(result); }
private Stream GetImageContent() { IMaterialContentPersistManager materialManager = MaterialContentSettings.GetConfig().PersistManager; //ImageProperty prop = ImagePropertyAdapter.Instance.Load(contentId); MemoryStream stream = (MemoryStream)materialManager.GetMaterialContent("14773f2f-2adf-4ddc-926f-eda3b1b47b11"); return(stream); }
private void EnsureNotChangedImage() { if (this._Content.ContentData == null) { IMaterialContentPersistManager manager = MaterialContentSettings.GetConfig().PersistManager; manager.DestFileInfo = ImagePropertyAdapter.Instance.GetPhysicalDestinationImagePath(this._Content.FileName); this._Content.ContentData = manager.GetMaterialContent(this._Content.ContentID).ToBytes(); } }
/// <summary> /// 下载模板或已存在的文件 /// </summary> public static void Download(object sender, BeforeFileDownloadHandler beforeDownloadHandler, PrepareDownloadStreamHandler prepareDownloadStreamHandler, bool raiseEvent) { ObjectContextCache.Instance["FileUploadProcessed"] = true; HttpResponse response = HttpContext.Current.Response; bool fileReadonly = WebUtility.GetRequestQueryValue <bool>("fileReadonly", false); string materialID = string.Empty; try { string controlID = WebUtility.GetRequestQueryValue("controlID", string.Empty); FileDownloadInfo downloadInfo = FileDownloadInfo.CollectInfoFromRequest(); if (File.Exists(downloadInfo.FileFullPath) == false) { //是否需要启用映射机制(归档后,文件根目录的映射) string mappedRootPath = AppPathMappingContext.GetMappedPathName(downloadInfo.RootPathName); downloadInfo.FileFullPath = GetFileFullPath(downloadInfo.PathType, mappedRootPath, downloadInfo.FilePath); } response.ContentType = FileConfigHelper.GetFileContentType(downloadInfo.FileName); materialID = WebUtility.GetRequestQueryValue("materialID", string.Empty); if (materialID.IsNullOrEmpty()) { materialID = UuidHelper.NewUuidString(); } if (fileReadonly) { WebFileOpenMode openMode = FileConfigHelper.GetFileOpenMode(downloadInfo.FileName, downloadInfo.UserID); response.AppendHeader("content-disposition", string.Format("{0};filename={1}", openMode == WebFileOpenMode.Inline ? "inline" : "attachment", response.EncodeFileNameInContentDisposition(downloadInfo.FileName))); } else { string fileIconPath = FileConfigHelper.GetFileIconPath(downloadInfo.FileName); response.AppendHeader("fileIconPath", HttpUtility.UrlEncode("message=" + fileIconPath)); response.AppendHeader("content-disposition", "attachment;fileName=" + response.EncodeFileNameInContentDisposition(downloadInfo.FileName)); if (downloadInfo.PathType != PathType.relative) { response.AppendHeader("materialID", "message=" + materialID); } } bool responseFile = true; if (beforeDownloadHandler != null && raiseEvent) { responseFile = beforeDownloadHandler(sender, downloadInfo); } if (responseFile) { IMaterialContentPersistManager persistManager = GetMaterialContentPersistManager(materialID, new FileInfo(downloadInfo.FileFullPath)); using (Stream stream = persistManager.GetMaterialContent(materialID)) { if (prepareDownloadStreamHandler != null && raiseEvent) { PrepareDownloadStreamEventArgs args = new PrepareDownloadStreamEventArgs(); args.DownloadInfo = downloadInfo; args.InputStream = stream; args.OutputStream = response.OutputStream; prepareDownloadStreamHandler(sender, args); } else { stream.CopyTo(response.OutputStream); } } } Control control = null; if (controlID.IsNotEmpty()) { control = WebControlUtility.FindControlByID((Page)HttpContext.Current.CurrentHandler, controlID, true); } if (control != null && control is MaterialControl) { DownloadEventArgs args = new DownloadEventArgs(materialID, downloadInfo.FilePath); ((MaterialControl)control).OnDownloadFile(args); } } catch (Exception ex) { if (fileReadonly) { response.Write(ex.Message); } else { GenerateErrorInformation(ex.ToString()); } } finally { try { response.End(); } catch { } } }