public void ExportAttachment(int attachmentNumber, string sourceFolder, string sourceFilename, byte[] content) { if (_ParentFormatter != null) { string sAttachmentNumber = attachmentNumber.ToString(); string sContent = Convert.ToBase64String(content); _ParentFormatter.ExportField(string.Format("Attachment{0}Folder", sAttachmentNumber), sourceFolder); _ParentFormatter.ExportField(string.Format("Attachment{0}Filename", sAttachmentNumber), sourceFilename); _ParentFormatter.ExportField(string.Format("Attachment{0}Content", sAttachmentNumber), sContent); } }
public void ExportAttachment(int attachmentNumber, string sourceFolder, string sourceFilename, byte[] content) { //following changes made by Amrit to create folder structure string sPath = System.IO.Path.Combine(_AttachmentFolder, sourceFolder.Replace("/", "\\")); if (!System.IO.Directory.Exists(sPath)) { System.IO.Directory.CreateDirectory(sPath); } sPath = System.IO.Path.Combine(sPath, sourceFilename); if (System.IO.File.Exists(sPath)) { int nCollisionCounter = 2; string sExtension = System.IO.Path.GetExtension(sourceFilename); string sFilename = System.IO.Path.GetFileNameWithoutExtension(sourceFilename); do { sPath = System.IO.Path.Combine(_AttachmentFolder, string.Format("{0} ({1}){2}", sFilename, nCollisionCounter.ToString(), sExtension)); nCollisionCounter++; }while (System.IO.File.Exists(sPath)); } using (System.IO.FileStream oCurrentRowStream = System.IO.File.Create(sPath)) { oCurrentRowStream.Write(content, 0, content.Length); } if (_ParentFormatter != null) { string sAttachmentNumber = attachmentNumber.ToString(); _ParentFormatter.ExportField(string.Format("Attachment{0}Folder", sAttachmentNumber), sourceFolder); _ParentFormatter.ExportField(string.Format("Attachment{0}Filename", sAttachmentNumber), sourceFilename); _ParentFormatter.ExportField(string.Format("Attachment{0}ExportLocation", sAttachmentNumber), sPath); } }