示例#1
0
        private FileDataPackage GetAttachmentData(string Id)
        {
            FileDataPackage pkg = new FileDataPackage();

            Common.Attachment attachment = Common.Attachment.FetchById(Id);

            if (attachment == null || attachment.DataAttachments.Count == 0)
            {
                throw new ApplicationException("No attachment found with this ID (" + Id + ")");
            }

            pkg.MimeType = attachment.Mime;
            pkg.FileName = attachment.FileName;
            pkg.FileData = attachment.DataAttachments[0].Binary;

            return(pkg);
        }
示例#2
0
        private string SaveAttachmentData(HttpContext httpContext, HttpPostedFile file, string fileName, byte[] bte)
        {
            Common.Attachment attachment = Common.Attachment.Create();

            attachment.FileName = fileName;
            attachment.Mime     = file.ContentType;

            attachment.TableUrl = httpContext.Request["tableURL"];
            attachment.RecordId = httpContext.Request["recordId"];
            attachment.Web      = 1;

            Common.AttachmentData attachmentData = Common.AttachmentData.Create();
            attachmentData.Binary    = bte;
            attachmentData.VersionNo = 0.0;

            attachment.DataAttachments.Add(attachmentData);

            attachment.Save();

            return(attachment.Id);
        }