API Questions on Kentico API.
Version 6.x > API > Upload File With BizForm API View modes: 
User avatar
Member
Member
robert-tailor.co - 5/30/2012 7:48:52 PM
   
Upload File With BizForm API
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.

User avatar
Member
Member
nicolas.juteau-nexun - 5/31/2012 8:21:03 AM
   
RE:Upload File With BizForm API
Hi Robert,

As far as I know, you don't need to perform any API operation to include uploaded file in the BizForm notification e-mail.

In Kentico v6, just check the field Attach uploaded documents checkbox in the Notification email tab of your BizForm.

I verified in the Kentico v4.1 documentation and this option is there as well, so you should be ok with it.

Regards,
Nicolas