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(); } }