public static void CreateAttachment(string savePath, int organizationId, AttachmentProxy.References refType, LoginUser user, HttpWebResponse httpWebResponse) { Attachments attachments = new Attachments(user); Attachment attachment = attachments.AddNewAttachment(); attachment.RefType = refType; attachment.RefID = user.UserID; attachment.OrganizationID = organizationId; attachment.FileName = Path.GetFileName(savePath); attachment.Path = savePath; attachment.FileType = string.IsNullOrEmpty(httpWebResponse.ContentType) ? "application/octet-stream" : httpWebResponse.ContentType; attachment.FileSize = httpWebResponse.ContentLength; //attachment.FilePathID = 3; attachments.Save(); }
public static void CopyInsertedKBAttachments1(int actionID, int insertedKBTicketID, LoginUser loginUser) { Attachments attachments = new Attachments(loginUser); attachments.LoadKBByTicketID(insertedKBTicketID); if (attachments.Count > 0) { Attachments clonedAttachments = new Attachments(loginUser); foreach (Attachment attachment in attachments) { Attachment clonedAttachment = clonedAttachments.AddNewAttachment(); clonedAttachment.OrganizationID = attachment.OrganizationID; clonedAttachment.FileType = attachment.FileType; clonedAttachment.FileSize = attachment.FileSize; clonedAttachment.Description = attachment.Description; clonedAttachment.DateCreated = attachment.DateCreatedUtc; clonedAttachment.DateModified = attachment.DateModifiedUtc; clonedAttachment.CreatorID = attachment.CreatorID; clonedAttachment.ModifierID = attachment.ModifierID; clonedAttachment.RefType = attachment.RefType; clonedAttachment.SentToJira = attachment.SentToJira; clonedAttachment.ProductFamilyID = attachment.ProductFamilyID; clonedAttachment.FileName = attachment.FileName; clonedAttachment.RefID = actionID; clonedAttachment.FilePathID = attachment.FilePathID; string originalAttachmentRefID = attachment.RefID.ToString(); string clonedActionAttachmentPath = attachment.Path.Substring(0, attachment.Path.IndexOf(@"\Actions\") + @"\Actions\".Length) + actionID.ToString() + attachment.Path.Substring(attachment.Path.IndexOf(originalAttachmentRefID) + originalAttachmentRefID.Length); if (!Directory.Exists(Path.GetDirectoryName(clonedActionAttachmentPath))) { Directory.CreateDirectory(Path.GetDirectoryName(clonedActionAttachmentPath)); } clonedAttachment.Path = clonedActionAttachmentPath; File.Copy(attachment.Path, clonedAttachment.Path); } clonedAttachments.BulkSave(); } }
public static string SaveAttachment(LoginUser loginUser, string contentType, long contentLength, string directory, string fileName, AttachmentProxy.References _refType, int _refID, string description) { Attachments attachments = new Attachments(loginUser); Attachment attachment = attachments.AddNewAttachment(); attachment.RefType = _refType; attachment.RefID = _refID; attachment.OrganizationID = loginUser.OrganizationID; attachment.FileName = fileName; //attachment.Path = Path.Combine(directory, fileName); attachment.FilePathID = 3; attachment.FileType = string.IsNullOrEmpty(contentType) ? "application/octet-stream" : contentType; attachment.FileSize = contentLength; attachment.Description = description; Directory.CreateDirectory(directory); attachments.Save(); return(attachment.Path); }