private void btnSave_ServerClick(object sender, EventArgs e) { if (!Page.IsValid) { return; } if (FileId > 0) { fs.RenameFile(FileId, txtTitle.Text, textDescription.Text); fs.AllowFileHistory(FileId, cbKeepHistory.Checked); } else if (LinkId == 0 && ParentFolderId >= 0) { string data = string.Format("[InternetShortcut]\r\nURL={0}", txtLink.Text); MemoryStream memStream = new MemoryStream(); StreamWriter writer = new StreamWriter(memStream, Encoding.Unicode); writer.Write(data); writer.Flush(); memStream.Seek(0, SeekOrigin.Begin); string title = txtTitle.Text; string html_filename = Mediachase.UI.Web.Util.CommonHelper.GetHtmlFileTitle(title); if (html_filename.IndexOf(".url") < 0) { html_filename += ".url"; } fs.SaveFile(ParentFolderId, html_filename, textDescription.Text, memStream); } CommandParameters cp = new CommandParameters("FL_NewLinkItem"); if (Request["PrimaryKeyId"] != null) { cp.CommandName = "FL_Storage_EditFileItem"; Mediachase.Ibn.Web.UI.WebControls.CommandHandler.GetCloseOpenedFrameScript(this.Page, cp.ToString()); } else { if (Request["New"] != null) { Mediachase.Ibn.Web.UI.WebControls.CommandHandler.GetCloseOpenedFrameScript(this.Page, cp.ToString()); } else { CHelper.CloseItAndRefresh(Response); } } }
private void Process() { string _containerName = "FileLibrary"; string _containerKey = "EMailAttach"; CS.BaseIbnContainer bic = CS.BaseIbnContainer.Create(_containerName, _containerKey); CS.FileStorage fs = (CS.FileStorage)bic.LoadControl("FileStorage"); CS.DirectoryInfo di = fs.GetDirectory(fs.Root.Id, guid, true); for (int Index = 0; Index < Request.Files.Count; Index++) { if (!String.IsNullOrEmpty(Request.Files[Index].FileName)) { using (McHttpPostedFile PostedFile = new McHttpPostedFile(Request.Files[Index])) { if (PostedFile.InputStream != null) { fs.SaveFile(di.Id, PostedFile.FileName, PostedFile.InputStream); } } } } }
protected void UploadMsgFile(FileStorage storage, int FolderId, int UserId, Pop3Message message) { System.Reflection.Assembly asm = typeof(FileExtendedPop3MessageHandler).Assembly; using (Stream stream = asm.GetManifestResourceStream("Mediachase.IBN.Business.Resources.template.msg")) { using(MemoryStream memStream = new MemoryStream()) { using (MsgHelper helper = new MsgHelper(stream)) { //helper.SetHtmlBody(message.From.Email); helper.SetSubject(message.Subject); helper.SetBody(message.BodyText); if (message.BodyHtml==null || message.BodyHtml.Trim()==String.Empty) { helper.SetHtmlBody(message.BodyText); } else helper.SetHtmlBody(message.BodyHtml); MailAddress from = message.Sender; if (from == null) from = message.From; helper.SetSenderEmail(from.Address); helper.SetSenderName(from.DisplayName); helper.SetReceiverName(message.To); helper.SetDisplayTo(message.To); helper.SetCreationTimes(DateTime.UtcNow); helper.Commit(); helper.createMSG(memStream); memStream.Flush(); memStream.Seek(0,SeekOrigin.Begin); string FileName = "Original_Message.msg"; int index = 0; while (storage.FileExist(FileName, FolderId)) { FileName = String.Format("Original_Message{0}.msg", index++); } storage.SaveFile(FolderId, FileName, string.Empty, UserId, DateTime.Now, memStream); } } } }
protected void UploadMhtFile(FileStorage storage, int FolderId, int UserId, Pop3Message message) { MHTHelper helper = new MHTHelper(message); using(MemoryStream memStream = new MemoryStream()) { using (StreamWriter writer = new StreamWriter(memStream)) { helper.CreateMHT(writer); writer.Flush(); memStream.Seek(0,SeekOrigin.Begin); string FileName = "Original_Message.mht"; int index = 0; while (storage.FileExist(FileName, FolderId)) { FileName = String.Format("Original_Message{0}.mht", index++); } storage.SaveFile(FolderId, FileName, string.Empty, UserId, DateTime.Now, memStream); } } }
protected void UploadEmlFile(FileStorage storage, int FolderId, int UserId, Pop3Message message) { message.InputStream.Position = 0; string FileName = "Original_Message.eml"; int index = 0; while (storage.FileExist(FileName, FolderId)) { FileName = String.Format("Original_Message{0}.eml", index++); } storage.SaveFile(FolderId, FileName, string.Empty, UserId, DateTime.Now, message.InputStream); }
protected void UploadAttachments(FileStorage storage, int FolderId, ArrayList attach, int UserId) { foreach(MimeEntry entry in attach ) { string FileName = entry.FileName; if (FileName == null) { if (entry.ContentType != null) { if(entry.ContentType.StartsWith("text/html")) continue; Hashtable parametrs = new Hashtable(); Regex contentParser = new Regex("(?<type>[^;]+)(;(\\s)*(?<parameter>((?<attribute>[^=]+)=(?<value>((\"[^\"]*\")?[^;]*)))))*"); Match match = contentParser.Match(entry.ContentType); string Type = match.Groups["type"].Value; int CaptureLen = match.Groups["parameter"].Captures.Count; for(int iIndex=0;iIndex<CaptureLen;iIndex++) { parametrs[match.Groups["attribute"].Captures[iIndex].Value.ToLower()] = match.Groups["value"].Captures[iIndex].Value.Replace("\"",""); } FileName = (string)parametrs["name"]; } if(FileName==null) FileName = string.Format("{0}.dat",(new Random()).Next()); } using(MemoryStream memStream = new MemoryStream(entry.Body)) { storage.SaveFile(FolderId, FileName, string.Empty, UserId, DateTime.Now, memStream); } } }
protected void btnSubmit_Click(object sender, System.EventArgs e) { bool withResponse = false; if (this.IsPostBack) { try { string sUserLight = "userlight"; // check user's name and password here UserLight currentUser = Security.GetUser(Login.Value, Password.Value); if (currentUser == null) { throw new HttpException(405, "Your login or password is invalid."); } // Security Addon [3/2/2004] UserLight retUser = null; if (HttpContext.Current.Items.Contains(sUserLight)) { retUser = (UserLight)HttpContext.Current.Items[sUserLight]; HttpContext.Current.Items.Remove(sUserLight); } HttpContext.Current.Items.Add(sUserLight, currentUser); // End Security Addon [3/2/2004] // New Folder System Addon [12/27/2005] string ContainerName = "FileLibrary"; string ContainerKey = String.Empty; int objectId = Int32.Parse(ObjectId.Value); int objectTypeId = Int32.Parse(ObjectTypeId.Value); int folderId = 0; switch ((ObjectTypes)objectTypeId) { case ObjectTypes.Project: ContainerKey = "ProjectId_" + objectId.ToString(); break; case ObjectTypes.Issue: ContainerKey = string.Empty; break; case ObjectTypes.Task: ContainerKey = "TaskId_" + objectId.ToString(); break; case ObjectTypes.CalendarEntry: ContainerKey = "EventId_" + objectId.ToString(); break; case ObjectTypes.Folder: ContainerKey = "Workspace"; if (objectId != 0) { folderId = objectId; ContainerKey = Mediachase.IBN.Business.ControlSystem.DirectoryInfo.GetContainerKey(folderId); } break; case ObjectTypes.Document: ContainerKey = "DocumentId_" + objectId.ToString(); break; case ObjectTypes.ToDo: ContainerKey = "ToDoId_" + objectId.ToString(); break; } if (ContainerKey != String.Empty) { Mediachase.IBN.Business.ControlSystem.BaseIbnContainer bic = Mediachase.IBN.Business.ControlSystem.BaseIbnContainer.Create(ContainerName, ContainerKey); Mediachase.IBN.Business.ControlSystem.FileStorage fs = (Mediachase.IBN.Business.ControlSystem.FileStorage)bic.LoadControl("FileStorage"); if (folderId == 0) { folderId = fs.Root.Id; } string fileName = Path.GetFileName(PublishedFile.PostedFile.FileName); if (FileName.Value != string.Empty) { fileName = FileName.Value; } /*int index = 0; * while (fs.FileExist(fileName, folderId)) * { * fileName = Path.GetFileNameWithoutExtension(PublishedFile.PostedFile.FileName) + (index++).ToString(); * fileName += Path.GetExtension(PublishedFile.PostedFile.FileName); * }*/ fs.SaveFile(folderId, fileName, PublishedFile.PostedFile.InputStream); } else if ((ObjectTypes)objectTypeId == ObjectTypes.List) { string xml = SaveNParseExcel(PublishedFile.PostedFile.FileName, PublishedFile.PostedFile.InputStream); Response.BinaryWrite(System.Text.Encoding.UTF8.GetBytes(xml)); withResponse = true; } else if ((ObjectTypes)objectTypeId == ObjectTypes.Issue) { string fileName = Path.GetFileName(PublishedFile.PostedFile.FileName); if (FileName.Value != string.Empty) { fileName = FileName.Value; } // OZ: 2008-08-19 Add Process Eml Attachments if (Path.GetExtension(fileName).ToLower() == ".eml") { // Calculate email box int emailBoxId = EMailRouterOutputMessage.FindEMailRouterPublicId(objectId); // Save Email to email storage int eMailMessageId = EMailMessage.CreateFromStream(emailBoxId, PublishedFile.PostedFile.InputStream); EMailMessage.AddToIncidentMessage(false, objectId, eMailMessageId); try { ArrayList excludeUsers = EMailRouterOutputMessage.Send(objectId, eMailMessageId); SystemEvents.AddSystemEvents(SystemEventTypes.Issue_Updated_Forum_MessageAdded, objectId, -1, excludeUsers); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine(ex); //Log.WriteError(ex.ToString()); } } // Process Default files else { BaseIbnContainer destContainer = BaseIbnContainer.Create("FileLibrary", string.Format("IncidentId_{0}", objectId)); ForumStorage forumStorage = (ForumStorage)destContainer.LoadControl("ForumStorage"); ForumThreadNodeInfo info = forumStorage.CreateForumThreadNode(string.Empty, Security.CurrentUser.UserID, (int)ForumStorage.NodeContentType.TextWithFiles); BaseIbnContainer forumContainer = BaseIbnContainer.Create("FileLibrary", string.Format("ForumNodeId_{0}", info.Id)); FileStorage fs = (FileStorage)forumContainer.LoadControl("FileStorage"); fs.SaveFile(fileName, PublishedFile.PostedFile.InputStream); ForumThreadNodeSettingCollection settings1 = new ForumThreadNodeSettingCollection(info.Id); settings1.Add(ForumThreadNodeSetting.Internal, "1"); } } // End New Folder System Addon [12/27/2005] // Security Addon [3/2/2004] HttpContext.Current.Items.Remove(sUserLight); HttpContext.Current.Items.Add(sUserLight, retUser); // End Security Addon [3/2/2004] } catch (Exception ex) { throw new HttpException(405, "Internal Exception", ex); } if (!withResponse) { this.Response.Write("Published Completed"); } this.Response.End(); } }