/// <summary> /// 设置TreeNode的属性 /// </summary> /// <param name="node">TreeNode</param> /// <param name="materialNode">MaterialTreeNode</param> private void InitNode(DeluxeTreeNode node, MaterialTreeNode materialNode) { node.ToolTip = "点击打开文件"; node.Expanded = true; node.SelectedCssClass = " "; node.Html = string.Format("[{0}]<a href=\"{1}?requestType=download&rootPathName={2}&controlID={3}&fileName={4}&pathType={5}&filePath={6}&fileReadonly=true&userID={7}\" target=\"_blank\" >{8}</a>", (materialNode.Material.Department != null) ? materialNode.Material.Department.DisplayName : string.Empty, this.CurrentPageUrl, WebUtility.GetRequestQueryValue("rootPathName", string.Empty), WebUtility.GetRequestQueryValue("controlID", string.Empty), materialNode.Material.OriginalName, Convert.ToInt16(PathType.relative), HttpUtility.UrlEncode(materialNode.Material.RelativeFilePath), this.userID, HttpUtility.HtmlEncode(materialNode.Material.Title)); if (!string.IsNullOrEmpty(materialNode.Material.RelativeFilePath)) { string fileName = Path.GetFileName(materialNode.Material.RelativeFilePath); string fileIconPath = FileConfigHelper.GetFileIconPath(fileName); if (fileIconPath != string.Empty) { node.NodeCloseImg = fileIconPath; node.NodeOpenImg = fileIconPath; } } }
//private IOrganization JSONSerializerExecute(OguOrganization OguOrganization) //{ // throw new Exception("The method or operation is not implemented."); //} /// <summary> /// 序列化material /// </summary> /// <param name="obj">material对象</param> /// <param name="serializer">序列化器</param> /// <returns>属性集合</returns> public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); Material material = (Material)obj; dictionary.Add("id", material.ID); //dictionary.Add("department", JSONSerializerExecute.Serialize(material.Department)); dictionary.Add("resourceID", material.ResourceID); dictionary.Add("sortID", material.SortID); dictionary.Add("materialClass", material.MaterialClass); dictionary.Add("title", material.Title); dictionary.Add("pageQuantity", material.PageQuantity); dictionary.Add("relativeFilePath", material.RelativeFilePath); dictionary.Add("originalName", material.OriginalName); //OguUser creator = (OguUser)material.Creator; //creator.DisplayName = DisplayName; //dictionary.Add("creator", JSONSerializerExecute.Serialize(creator)); dictionary.Add("lastUploadTag", material.LastUploadTag); dictionary.Add("createDateTime", material.CreateDateTime); dictionary.Add("modifyTime", material.ModifyTime); dictionary.Add("wfProcessID", material.WfProcessID); dictionary.Add("wfActivityID", material.WfActivityID); dictionary.Add("wfActivityName", material.WfActivityName); dictionary.Add("parentID", material.ParentID); dictionary.Add("sourceMaterial", material.SourceMaterial); dictionary.Add("versionType", material.VersionType); dictionary.Add("extraData", material.ExtraDataDictionary); dictionary.Add("fileIconPath", FileConfigHelper.GetFileIconPath(material.OriginalName)); dictionary.Add("showFileUrl", material.ShowFileUrl); dictionary.Add("selected", false); return(dictionary); }
/// <summary> /// 上传 /// </summary> public static void Upload() { ObjectContextCache.Instance["FileUploadProcessed"] = true; HttpRequest request = HttpContext.Current.Request; HttpResponse response = HttpContext.Current.Response; string lockID = WebUtility.GetRequestQueryValue <string>("lockID", string.Empty); string userID = WebUtility.GetRequestQueryValue <string>("userID", string.Empty); string fileName = WebUtility.GetRequestQueryValue <string>("fileName", string.Empty); int fileMaxSize = WebUtility.GetRequestQueryValue <int>("fileMaxSize", 0); string controlID = WebUtility.GetRequestQueryValue("controlID", string.Empty); ExceptionHelper.CheckStringIsNullOrEmpty(fileName, "fileName"); try { if (fileMaxSize > 0 && request.ContentLength > fileMaxSize) { GenerateErrorInformation(string.Format("文件超过了上传大小的限制{0}字节", fileMaxSize)); } else { //不检查锁,沈峥修改 //CheckLock(lockID, userID); string uploadPath = GetUploadRootPath(); AutoCreateUploadPath(uploadPath); Control control = null; if (string.IsNullOrEmpty(controlID) == false) { control = WebControlUtility.FindControlByID((Page)HttpContext.Current.CurrentHandler, controlID, true); } string newID = UuidHelper.NewUuidString(); if (fileName.IndexOf(NewMaterialID) == 0) { fileName = fileName.Replace(NewMaterialID, newID); } else { newID = Path.GetFileNameWithoutExtension(fileName); } if (control != null && control is MaterialControl) { UploadEventArgs args = new UploadEventArgs(fileName); ((MaterialControl)control).OnBeforeUploadFile(args); } if (request.QueryString["upmethod"] == "new") { var dialogControlID = WebUtility.GetRequestQueryValue("dialogControlID", string.Empty); request.Files[0].SaveAs(uploadPath + @"Temp\" + fileName); string output = "<script type='text/javascript'>"; output += "window.parent.$find('" + dialogControlID + "').onUploadFinish(1)"; output += "</script>"; response.Write(output); } else { request.SaveAs(uploadPath + @"Temp\" + fileName, false); } if (control != null && control is MaterialControl) { UploadEventArgs args = new UploadEventArgs(fileName); ((MaterialControl)control).OnAfterUploadFile(args); } string fileIconPath = FileConfigHelper.GetFileIconPath(fileName); response.AppendHeader("fileIconPath", HttpUtility.UrlEncode("message=" + fileIconPath)); string dateTimeNow = SNTPClient.AdjustedTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); response.AppendHeader("lastUploadTag", "message=" + dateTimeNow); response.AppendHeader("newMaterialID", "message=" + HttpUtility.UrlEncode(newID)); } } catch (Exception ex) { string errorMessage = ex.ToString(); if (ex is ExternalException && ((ExternalException)(ex)).ErrorCode == FileTooLargeError && ex.Source == "System.Web") { errorMessage = "您上传的文件过大"; } GenerateErrorInformation(errorMessage); } finally { try { response.End(); } catch { } } }
/// <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 { } } }
private void UploadImage() { const int FileTooLargeError = -2147467259; ObjectContextCache.Instance["FileUploadProcessed"] = true; HttpRequest request = HttpContext.Current.Request; HttpResponse response = HttpContext.Current.Response; string lockID = WebUtility.GetRequestQueryValue <string>("lockID", string.Empty); string userID = WebUtility.GetRequestQueryValue <string>("userID", string.Empty); string fileName = WebUtility.GetRequestQueryValue <string>("fileName", string.Empty); int fileMaxSize = WebUtility.GetRequestQueryValue <int>("fileMaxSize", 0); string controlID = WebUtility.GetRequestQueryValue("controlID", string.Empty); ExceptionHelper.CheckStringIsNullOrEmpty(fileName, "fileName"); try { if (fileMaxSize > 0 && request.ContentLength > fileMaxSize) { GenerateErrorInformation(string.Format("文件超过了上传大小的限制{0}字节", fileMaxSize)); } else { //不检查锁,沈峥修改 //CheckLock(lockID, userID); string uploadPath = ImageUploadHelper.GetUploadRootPath(this.RootPathName); AutoCreateUploadPath(uploadPath); string newID = UuidHelper.NewUuidString(); fileName = newID + fileName.Substring(fileName.LastIndexOf('.')); if (WebUtility.GetRequestQueryString("upmethod", "") == "new") { var dialogControlID = WebUtility.GetRequestQueryValue("dialogControlID", string.Empty); request.Files[0].SaveAs(uploadPath + @"Temp\" + fileName); string output = "<script type='text/javascript'>"; output += "window.parent.$find('" + dialogControlID + "').onUploadFinish(1)"; output += "</script>"; response.Write(output); } else if (WebUtility.GetRequestQueryString("upmethod", "") == "ue") { request.Files[0].SaveAs(uploadPath + @"Temp\" + fileName); string output = "<script type='text/javascript'>"; output += string.Format("window.parent.onUploadFinish('{0}','{1}')", newID, fileName); output += "</script>"; response.Write(output); } else { request.SaveAs(uploadPath + @"Temp\" + fileName, false); } string fileIconPath = FileConfigHelper.GetFileIconPath(fileName); response.AppendHeader("fileIconPath", HttpUtility.UrlEncode("message=" + fileIconPath)); string dateTimeNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); response.AppendHeader("lastUploadTag", "message=" + dateTimeNow); response.AppendHeader("newMaterialID", "message=" + HttpUtility.UrlEncode(newID)); } } catch (Exception ex) { string errorMessage = ex.Message; if (ex is ExternalException && ((ExternalException)(ex)).ErrorCode == FileTooLargeError && ex.Source == "System.Web") { errorMessage = "您上传的文件过大"; } GenerateErrorInformation(errorMessage); } finally { try { response.End(); } catch { } } }