Hey Brenden,
That was exactly what I was needing, thank you. A follow up question. I also need to attach these uploaded document to the notification email. My code looks as follows
private void SendEmail(BizFormInfo bfi, DataClassInfo dci, int id)
{
if (!string.IsNullOrEmpty(bfi.FormSendFromEmail) && !string.IsNullOrEmpty(bfi.FormSendToEmail))
{
bfi.FormEmailAttachUploadedDocs = true;
BizForm f = new BizForm();
IDataClass content = DataClassFactory.NewDataClass(dci.ClassName, id);
f.SendNotificationEmail(
bfi.FormSendFromEmail,
bfi.FormSendToEmail,
content, bfi);
}
}
The email sends fine, however the documents don't get attached. Taking a look at CMS.OnlineForms.Web.UI.dll
I found the SendNotificationEmail
method.
public virtual void SendNotificationEmail(string fromEmail, string recipients, IDataContainer data, BizFormInfo bfi) {
...
if (bfi.FormEmailAttachUploadedDocs)
{
string bizFormFilesFolderPath = FormHelper.GetBizFormFilesFolderPath(base.SiteName, null);
foreach (string uploadFile in this.uploadFiles)
{
string str2 = Convert.ToString(data.GetValue(uploadFile));
if (string.IsNullOrEmpty(str2))
{
continue;
}
string str3 = string.Concat(bizFormFilesFolderPath, FormHelper.GetGuidFileName(str2));
if (!File.Exists(str3))
{
continue;
}
Attachment attachment = new Attachment(FileStream.New(str3, FileMode.Open, FileAccess.Read), this.GetFileNameForUploader(str2));
emailMessage.Attachments.Add(attachment);
}
}
...
}
I can't debug the dll, but my best guess is that this.uploadFiles
isn't returning anything. Currently I'm saving the file to FormHelper.GetBizFormFilesFolderPath(SiteContext.CurrentSiteName);
and then saving the string reference (<GUID>.<extension>/<orig_name>.<extension>
) to the form. I'm guessing though that Kentico doesn't know I want to link a file to a form. Is there a method to achieve this?