Alexander Staroselsky
Alexander Staroselsky

Reputation: 38777

Kentico - BizForm File Field Attachment/Upload URL

For a BizForm field of type File using an Upload file control, the recorded submission data for the field is being saved as a string similar to a value of a858eda6-4699-4bda-81d0-1b85d69aa9a7.pdf/test.pdf for a PDF with a name of test.pdf with a field with a code name of Foo. I am trying to get the URL for that uploaded document for a given BizForm submission. Trying to access the attachment using the following URLs result 404 errors:

https://somesite.com/getattachment/a858eda6-4699-4bda-81d0-1b85d69aa9a7.pdf/test.pdf
https://somesite.com/getattachment/a858eda6-4699-4bda-81d0-1b85d69aa9a7.pdf/test.pdf.aspx
https://somesite.com/CMSPages/GetFile.aspx?guid=a858eda6-4699-4bda-81d0-1b85d69aa9a7

How can the URL be built to access a given BizForm submission's File field that uses the Upload file control for a field with a code name of Foo? And/or how can be accessed from code behind if I know the BizForm submission's ID in something like a BizFormItemEvents.Insert.After handler.

Thank you for any help you can provide.

Upvotes: 1

Views: 819

Answers (1)

Peter Mogilnitski
Peter Mogilnitski

Reputation: 998

Try https://somesite.com/CMSPages/GetBizFormFile.aspx?filename=a858eda6-4699-4bda-81d0-1b85d69aa9a7.pdf

you can try macro like:

{%  
row = Siteobjects.Forms["FormCodeName"].Items.Where("ItemId = 123").FirstItem;
row["attachmentFieldname"]
#%}

Here is an old link to work with biz form files, most of it is still valid. it will give some ideas. Here is a link to GetBizFormFile.aspx.cs

Using API it should pretty straight forward:

var filepath =  BizFormItemProvider.GetItems(formClassName)
.Where("itemid = 123")
.AsEnumerable().FirstOrDefault().GetValue("FileField")    

You will get the same format: <GUID>.<extension>/<orig_name>.<extension>. Then you can parse and make URL out of it ~/CMSPages/GetBizFormFile.aspx?filename=<GUID>.<extension>

Upvotes: 1

Related Questions