Hi,
I'm using a custom BizForm that includes a file upload option, and then I want to email the data from that BizForm to an email address specified in the BizForm 'Notification E-Mail' screen.
How do I attach an uploaded file to the BizForm email? The API is very unclear on how to do this.
As I understand it, the file has to be uploaded to a specified node first, as outlined here: http://devnet.kentico.com/docs/5_5/devguide/index.html?managing_attachments.htm
NOTE: I am selecting a node at "/Images/Other-Images", but the line 'node.SetValue("FileAttachment", attachmentGuid);" throws a null reference exception (even though neither node or attachmentGuid are null).
Assuming that works, I should then be able to do something like:
using CMS.SiteProvider;
using CMS.TreeEngine;
using CMS.CMSHelper;
using CMS.FileManager;
// Always work with some user when editing documents
UserInfo ui = UserInfoProvider.GetUserInfo("administrator");
TreeProvider tree = new TreeProvider(ui);
// First, get the document
CMS.TreeEngine.TreeNode node =
tree.SelectSingleNode(CMSContext.CurrentSite.SiteName, "/Images/Other-Images", "en-us");
if (node != null)
{
// Create the attachment manager
AttachmentManager am = new AttachmentManager(tree.Connection);
// Create the attachment
Guid attachmentGuid = Guid.NewGuid();
AttachmentInfo ai = new AttachmentInfo("CMSFileUpload.PostedFile", node.DocumentID, attachmentGuid, tree.Connection);
am.SetAttachmentInfo(ai);
// Set the attachment reference
// (NULL REFERENCE EXCEPTION HERE! WHY??
node.SetValue("FileAttachment", attachmentGuid);
node.Update();
// Attach file to BizForm upload
BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo("MyBizForm", CMS.CMSHelper.CMSContext.CurrentSiteName);
bfi.SetValue("UploadFile1", ai);
}
However, this does not work. The email is sent out without an attachment, and the '/Images/Other-Images' folder does not contain the uploaded image.
I am using Kentico v4.1.
Thanks.