Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > attachments in bizforms View modes: 
User avatar
Certified Marketer 13
Certified Marketer 13
bruce.williams-thundertech - 3/22/2013 2:21:35 PM
   
attachments in bizforms
I cant get a created attachment for a form record submission.

I am using following code in custom biz form. Created my own control.

I have a fileupload field (Upload File) in the defined biz form:
string bizFormName = "JobsForm"; //name of your form in cms desk
string siteName = CMS.CMSHelper.CMSContext.CurrentSite.SiteName;

BizFormInfo bfi = BizFormInfoProvider.GetBizFormInfo(bizFormName, siteName);
try
{
if (bfi != null)
{
// Read data type definition
DataClassInfo dci = DataClassInfoProvider.GetDataClass(bfi.FormClassID);

if (dci != null)
{
IDataClass formRecord = DataClassFactory.NewDataClass(dci.ClassName);

formRecord.SetValue("FirstName", FirstName.Text);
formRecord.SetValue("LastName", LastName.Text);
formRecord.SetValue("Email", Email.Text);
formRecord.SetValue("Phone", Phone.Text);
formRecord.SetValue("JobName", JobName.SelectedValue);

CMS.DocumentEngine.AttachmentInfo ai = new CMS.DocumentEngine.AttachmentInfo(Resume.PostedFile);
ai.AttachmentSiteID = CMS.CMSHelper.CMSContext.CurrentSite.SiteID;
CMS.DocumentEngine.AttachmentInfoProvider.SetAttachmentInfo(ai);
formRecord.SetValue("Resume", ai.AttachmentName);
formRecord.SetValue("FormInserted", DateTime.UtcNow);
formRecord.SetValue("FormUpdated", DateTime.UtcNow);
CMS.FormControls.BizForm form = new CMS.FormControls.BizForm();

error.Text = getValidation();
if (String.IsNullOrEmpty(error.Text))
{
formRecord.Insert();
bfi.FormItems++;
bfi.SubmitChanges(false);
form.SendNotificationEmail(bfi.FormSendFromEmail, bfi.FormSendToEmail, formRecord, bfi);
Response.Redirect(bfi.FormRedirectToUrl);
}
}
}
}
catch (Exception ex)
{

error.Text = ex.Message;
}





It saves great, but when the link comes up, through this file:
/CMSModules/BizForms/CMSPages/GetBizFormFile.aspx?filename=EI_Lead_Generation_Requirements_01_29_13.docx&sitename=FortecMedical

It doesn’t find the server path.

I configured the file paths appropriately in Site Manager, or so I think:

This is what filepath it is looking for:
C:\inetpub\sites\fortec\fortecmedical.com\fortecmedical\custom\FortecMedical\EI_Lead_Generation_Requirements_01_29_13.docx

The highlighted is not even existing directories, yet the GetBizFormFile.aspx attempts to look for it through:

if (CurrentUser != null && CurrentUser.IsAuthorizedPerResource("cms.form", "ReadData"))
{
// Get file name from querystring.
string fileName = QueryHelper.GetString("filename", String.Empty);
string siteName = QueryHelper.GetString("sitename", CurrentSiteName);

if ((ValidationHelper.IsFileName(fileName)) && (siteName != null))
{
// Get physical path to the file.
string filePath = FormHelper.GetFilePhysicalPath(siteName, fileName);

if (File.Exists(filePath))
{

// Clear response.
CookieHelper.ClearResponseCookies();
Response.Clear();

// Prepare response.
string extension = Path.GetExtension(filePath);
Response.ContentType = MimeTypeHelper.GetMimetype(extension);

// Set the file disposition
SetDisposition(fileName, extension);

// Get file binary from file system.
WriteFile(filePath);

CompleteRequest();
// RequestHelper.EndResponse();
}
else
{
Response.Write(filePath); //my code here
Response.End();
}
}
}