Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > BizForms file upload issue View modes: 
User avatar
Member
Member
Jagr - 3/30/2009 10:13:50 AM
   
BizForms file upload issue
Hi,

I have created a simple custom BizForm with a couple of textboxes and one file upload field.

Also, I added OnAfterSave event handler in which I am adding new node to the tree using data from the form. This node is custom document type, which also has attachment field.

I would like to use this uploaded file from BizForm, and put it as an attachment for my document type. But I can't find the way to do it.

Can anyone help with this issue?

Cheers :)

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 3/30/2009 11:11:46 AM
   
RE:BizForms file upload issue
Hi,

Have you tried to perform such operation using Kentico CMS API for attachmnets(http://www.kentico.com/docs/devguide/managing_attachments.htm)?

You can use for example CMS.FileManager. AttachmentInfo. AttachmentInfo(HttpPostedFile, Int32, Guid, GeneralConnection) method to create new AttachmentInfo object and then store it in appropriate document as it is described in above documentation.

Thank you.

Best Regards,
Miroslav Remias

User avatar
Member
Member
Jagr - 3/30/2009 2:15:41 PM
   
RE:BizForms file upload issue
Hi Miroslav,

Thanks for the reply.

My main problem is how to retrieve uploaded file from BizForm field. I tried with some of the BizForm methods but with no luck. Like in ASP.NET FileUpload control, where I can use property PostedFile. I need something like that.

I used that method from guide, and based on that I created my attachment. But I am missing a path to the file, because I want uploaded file from BizForm to be my attachment file for document.

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 3/30/2009 3:45:16 PM
   
RE:BizForms file upload issue
Hi,

I understand what you are trying to achieve. You are probably using FileUpload Kentico CMS control as BizForm control when uploading file to BizForm. This is the standard way, since FileUpload stands for CMS.ExtendedControls.CMSFileUpload control in 4.0 version and is has PostedFile property, so you are able to work with it the same way as standard ASP.NET FileUpload control.

I would recommend you to look at the following KB article on how to access the BizForm controls:

http://devnet.kentico.com/Knowledge-Base/Web-parts---Controls/Making-BizForm-fields-inactive-after-submitting.aspx

Then if you can access this FileUpload control, you can access its PostedFile property and you can use it in CMS.FileManager. AttachmentInfo. AttachmentInfo(HttpPostedFile, Int32, Guid, GeneralConnection) method to create new AttachmentInfo object and then use this object to store attachment to document.

Thank you.

Best regards,
Miroslav Remias.

User avatar
Member
Member
Jagr - 3/31/2009 5:14:41 AM
   
RE:BizForms file upload issue
Hi Miroslav,

Again, thanks a lot for your reply. It was really helpful to me, and you gave me the idea how to solve my problem.

I just want to make a few notes here.

I tried with CMS.ExtendedControls.CMSFileUpload control just like suggested in that KB article, but the control could not be found. Then I tried with CMS.ExtendedControls.Uploader and it worked fine. Then I suppose that this control is used for BizForms file upload and not CMSFileUploaded.

Uploader also have a property PostedFile so I used it for my problem.

Second thing that I wanted to express here is that I couldn't use this solution in OnAfterSave event, because then, BizForm is already cleared and I couldn't get the value of the PostedFile property. I was getting an error "object not set to an instance of an object".

I changed my architecture a bit and used this solution in OnBeforeSave event, and my problem was solved.

Actually it really doesn't matter to me if it is going to be done before or after saving BizForm. It is only important that it is done properly.

Anyway, again, thank you very much for help.

Cheers :)

User avatar
Kentico Consulting
Kentico Consulting
kentico_mirekr - 3/31/2009 7:04:38 AM
   
RE:BizForms file upload issue
Hi,

Yes, you are right about that BizForms (by default) are using CMS.ExtendedControls.Uploader control. This was just mistake in my explanation. Regarding the BizForm event, I just wanted to give you an idea how to access the controls. I didn't want you to use OnAfterSave event of BizForm. It was just an example on how to access the BizForm controls. You are definitely right that you need to use OnBeforeSave event to get proper PostedFile from your control.

Anyway, I'm glad that you have managed to solve your requirement.

Thank you.

Best Regards,
Miroslav Remias.