コード例 #1
0
        private void CreateAttachments(Post post)
        {
            foreach (var attachItem in _attachmentsString.Split(new string[] { "%$%" }, StringSplitOptions.RemoveEmptyEntries))
            {
                Attachment attachment        = new Attachment();
                var        attachmentOptions = attachItem.Split(new string[] { "$@$" }, StringSplitOptions.RemoveEmptyEntries);
                attachment.OffsetPhysicalPath = GetNotNullArrayItem(attachmentOptions, 0);

                if (_forumManager.GetStore().IsFile(attachment.OffsetPhysicalPath) == false)
                {
                    continue;
                }

                attachment.PostID          = post.ID;
                attachment.Name            = GetNotNullArrayItem(attachmentOptions, 1);
                attachment.Size            = Convert.ToInt32(GetNotNullArrayItem(attachmentOptions, 2));
                attachment.MIMEContentType = GetNotNullArrayItem(attachmentOptions, 3);

                attachment.ID = ForumDataProvider.CreateAttachment(TenantProvider.CurrentTenantID, post.ID, attachment.Name, attachment.OffsetPhysicalPath,
                                                                   attachment.Size, attachment.ContentType, attachment.MIMEContentType);

                post.Attachments.Add(attachment);
            }
        }