public void ProcessRequest(HttpContext context) { string postBackID = context.Request.Params["postBackID"]; string controlID = context.Request.Params["controlID"]; string cancel = context.Request.Params["cancel"]; if (cancel != null && Boolean.Parse(cancel)) { UploadModule.CancelPostBack(postBackID); } UploadModule.BindProgressState(postBackID, controlID, this); string message = ""; if (Status == UploadStatus.Rejected) { message = Rejection.Message; } else if (Status == UploadStatus.Failed) { message = Failure.Message; } context.Response.ContentType = "application/json"; double percentComplete = Math.Floor(100 * FractionComplete); string processingStateJson = "null"; ProgressInfo progressInfo = ProcessingState as ProgressInfo; if (progressInfo != null) { percentComplete = Math.Floor(100.0 * progressInfo.Value / progressInfo.Maximum); processingStateJson = String.Format(@"{{ ""Value"" : {0}, ""Maximum"" : {1}, ""Units"" : ""{2}"", ""Text"" : ""{3}"" }}", progressInfo.Value, progressInfo.Maximum, Quote(progressInfo.Units), progressInfo.Text != null ? Quote(progressInfo.Text) : ""); } System.Text.StringBuilder filesJson = new System.Text.StringBuilder(); bool isFirstFile = true; for (int i = 0; Files != null && i < Files.Count; i++) { UploadedFile file = Files[i]; if (Status == UploadStatus.NormalInProgress || Status == UploadStatus.ChunkedInProgress || Status == UploadStatus.ProcessingInProgress) { AppendFileJson(filesJson, file, ref isFirstFile); } else { // If the upload isn't in progress, the file might have been disposed which // can cause exceptions, so we only make a best effort. try { AppendFileJson(filesJson, file, ref isFirstFile); } catch (Exception ex) { // File was probably disposed so ignore the error. } } } string jsonFormat = @"{{ ""Status"" : ""{0}"", ""BytesRead"" : {1}, ""BytesTotal"" : {2}, ""PercentComplete"" : {3}, ""BytesPerSec"" : {4}, ""Message"" : ""{5}"", ""SecsRemaining"" : {6}, ""SecsElapsed"" : {7}, ""CurrentFileName"" : ""{8}"", ""ProcessingState"" : {9}, ""Files"" : [{10}] }} "; string json = String.Format(jsonFormat, Status, BytesRead, BytesTotal, percentComplete, BytesPerSec, Quote(message), Math.Floor(TimeRemaining.TotalSeconds), Math.Floor(TimeElapsed.TotalSeconds), Quote(CurrentFileName), processingStateJson, filesJson.ToString()); context.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); context.Response.Write(json); }
public static CFuJian Upload(UploadedFile file, string UCProcessType, string UCProcessID, string UCWorkItemID) { CFuJian cFuJian = new CFuJian(); OA_DocumentService api = MossObject.GetMOSSAPI(); string[] fileInfo = GetUploadFileInfo(UCProcessType, file.FileName); cFuJian.Type = System.IO.Path.GetExtension(file.FileName); //文件类型 扩展名 if (cFuJian.Type.IndexOf('.') > -1) { cFuJian.Type = cFuJian.Type.Substring(1); } cFuJian.Alias = file.FileName.Substring(0, file.FileName.Length - cFuJian.Type.Length - 1); //别名 //ff.Title = ff.Alias + "." + ff.Type; cFuJian.Title = fileInfo[3]; if (cFuJian.Type.Length == 0)//没有扩展名 { cFuJian.Alias = file.FileName; } cFuJian.Alias = cFuJian.Alias.Replace(" ", ""); cFuJian.FolderName = fileInfo[2]; cFuJian.FileName = fileInfo[3]; cFuJian.Size = MossObject.ToFileSize(file.ContentLength); //文件大小 cFuJian.ProcessType = UCProcessType; cFuJian.WorkItemID = UCWorkItemID; string[] saveUrl; #region DLL if (OAConfig.GetConfig("MOSS认证", "是否启用DLL") == "1") { #region 更新栏位 List<System.Collections.DictionaryEntry> lst = new List<System.Collections.DictionaryEntry>(); System.Collections.DictionaryEntry de = new System.Collections.DictionaryEntry(); de.Key = "流程实例"; de.Value = UCProcessID; lst.Add(de); de = new System.Collections.DictionaryEntry(); de.Key = "别名"; de.Value = cFuJian.Alias; lst.Add(de); de = new System.Collections.DictionaryEntry(); de.Key = "上次修改者"; de.Value = CurrentUserInfo.DisplayName; lst.Add(de); #endregion System.Collections.DictionaryEntry[] result = DocumentManager.ConvertToDE(lst.ToArray()); if (file.ContentLength <= MossObject.middleFileSize * 1024 * 1024) { saveUrl = DocumentManager.Upload(fileInfo, MossObject.StreamToBytes(file.InputStream), result, false); } else { string strFileTemp = "D:\\FileTemp\\"; if (System.IO.Directory.Exists(strFileTemp) == false) { System.IO.Directory.CreateDirectory(strFileTemp); } string fileTemp = strFileTemp + "OA" + Current.UserName + Path.GetFileNameWithoutExtension(file.TmpFile.Name); string filePath = fileTemp + file.FileName; p1: if (System.IO.File.Exists(filePath)) { filePath = fileTemp + new Random(1).Next(100).ToString() + file.FileName; goto p1; } else { file.TmpFile.MoveTo(filePath); } saveUrl = DocumentManager.Upload(fileInfo, filePath, result, false); File.Delete(filePath); } ////int ret = api.CopyTo(fileInfo, "322.doc", true); //file.TmpFile.Delete(); //删除临时文件 //cFuJian.fullURL = saveUrl[0]; //全路径 //cFuJian.URL = saveUrl[1];//文件夹+/文件名 //cFuJian.Encode = "";//文件编码 //return cFuJian; } #endregion #region webservice else { #region 更新栏位 List<DictionaryEntry> lst = new List<DictionaryEntry>(); DictionaryEntry de = new DictionaryEntry(); de.Key = "流程实例"; de.Value = UCProcessID; lst.Add(de); de = new DictionaryEntry(); de.Key = "别名"; de.Value = cFuJian.Alias; lst.Add(de); de = new DictionaryEntry(); de.Key = "上次修改者"; de.Value = CurrentUserInfo.DisplayName; lst.Add(de); #endregion DictionaryEntry[] result = api.ConvertToDE(lst.ToArray()); if (file.ContentLength <= MossObject.middleFileSize * 1024 * 1024) { //上传到文档库 saveUrl = api.Upload(fileInfo, MossObject.StreamToBytes(file.InputStream), result, false); } else { string strFileTemp = "D:\\FileTemp\\"; if (System.IO.Directory.Exists(strFileTemp) == false) { System.IO.Directory.CreateDirectory(strFileTemp); } string fileTemp = strFileTemp + "OA" + Current.UserName + Path.GetFileNameWithoutExtension(file.TmpFile.Name); string filePath = fileTemp + file.FileName; p1: if (System.IO.File.Exists(filePath)) { filePath = fileTemp + new Random(1).Next(100).ToString() + file.FileName; goto p1; } else { file.TmpFile.MoveTo(filePath); } saveUrl = api.Upload_New(fileInfo, filePath, result, false); File.Delete(filePath); } } #endregion file.TmpFile.Delete(); //删除临时文件 cFuJian.fullURL = saveUrl[0]; //全路径 cFuJian.URL = saveUrl[1];//文件夹+/文件名 cFuJian.Encode = "";//文件编码 return cFuJian; }
internal static void DisposeAtEndOfRequest(UploadedFile file) { HttpContext ctx = HttpContext.Current; if (ctx == null) return; // Not in an ASP.NET request, so nothing to do // Add a list of files to dispose to the current context if one hasn't been added yet ArrayList filesToDispose = ctx.Items["NeatUpload_FilesToDispose"] as ArrayList; if (filesToDispose == null) { filesToDispose = new ArrayList(); ctx.Items["NeatUpload_FilesToDispose"] = filesToDispose; } // Add the file to the list of files filesToDispose.Add(file); }
internal void Add(string key, UploadedFile file) { lock (_SyncRoot) { this.BaseAdd(key, file); } if (Changed != null) Changed(this, null); }