SaaS CMS has officially launched! Learn more now.

Anders Hattestad
Jan 8, 2013
  11248
(4 votes)

Upload within Xform

Sometimes one would like to enable users to upload files in a Xform. Based on my blog post about extending xforms, I have added an upload function.

I check if an textbox have a css class called FileUpload. If it has it will replace that textbox with an upload function.

clip_image002

So it will look something like this

clip_image002[5]

It handles also more than one file

clip_image002[7]

The stuff that will be saved is like this

clip_image002[9]

image

The code will upload files to a seperate VPP folder

      <add showInFileManager="true" virtualName="XformFiles"
        virtualPath="~/XformFiles/" bypassAccessCheck="true" 
           physicalPath="C:\EPiServer\VPP\XformFiles"
        name="XformFiles" type="EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer" />
I havent testet the code with CMS7 thou.
The code is uploaded here 
Jan 08, 2013

Comments

Daniel Pålsson
Daniel Pålsson Jan 9, 2013 08:47 AM

Looks really interesting, but how would you go about to attach the uploaded file to the outgoing mail?

Anders Hattestad
Anders Hattestad Jan 9, 2013 09:06 AM

That will be easy. Just attach to the BeforeSubmitPostedData event
Check if ((e.FormData.ChannelOptions & ChannelOptions.Email) != ChannelOptions.Email) is true
then send the custom mail and remove the send mail option
e.FormData.ChannelOptions &= ~ChannelOptions.Email;

Luc Gosso (MVP)
Luc Gosso (MVP) Jan 9, 2013 12:00 PM

You´ve made it easy for us, and it works! thats fantastic.

Except when you have validation on the field, then it always display empty.

I have tried to add the "oldFiles" to the field but it doesn't work. Any idea?

if (item.Attributes["value"] == null)
{
var value = item.OwnerDocument.CreateAttribute("value");
item.Attributes.Append(value);
}
item.Attributes["value"].Value = oldFiles;

Im hooked up with BeforeSubmitPostedData and that seems to be working.

Ive also noticed that the form editor is not working 100% in FF. Works in IE. Epi6 SP2.

Jonathan Roberts
Jonathan Roberts Jan 18, 2013 10:35 AM

Is there any way you can encrypt the form data before it is submitted into the database?

Graham Fieldhouse
Graham Fieldhouse Jul 16, 2013 04:33 PM

This is really useful, and it works in CMS7.1 without any changes.

Jinesh V
Jinesh V Feb 26, 2014 10:16 AM

Does this work for EPiServer 7.5?

Jonas Unosson
Jonas Unosson Sep 4, 2014 01:46 PM

Do you have some example code on how to attach the uploaded files to the BeforeSubmitPostedData event in Global.asax.cs?

I haven't succeeded to get it to work. The files are uploaded to the VPP folder, but I am not sure how to get it attached to the email.

Does anyone have some example code for this?

Marcus W
Marcus W Apr 28, 2015 03:55 PM

EPiServer 7.1

I had to add: useRouting="true" here to get it to Virtual map the file correctly.

"true" virtualName="XformFiles"
        virtualPath="~/XformFiles/" bypassAccessCheck="true" 
           physicalPath="C:\EPiServer\VPP\XformFiles"
        name="XformFiles" type="EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer"  useRouting="true"/>

Please login to comment.
Latest blogs
Optimizely SaaS CMS Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024

How to have a link plugin with extra link id attribute in TinyMce

Introduce Optimizely CMS Editing is using TinyMce for editing rich-text content. We need to use this control a lot in CMS site for kind of WYSWYG...

Binh Nguyen Thi | Jul 13, 2024

Create your first demo site with Optimizely SaaS/Visual Builder

Hello everyone, We are very excited about the launch of our SaaS CMS and the new Visual Builder that comes with it. Since it is the first time you'...

Patrick Lam | Jul 11, 2024

Integrate a CMP workflow step with CMS

As you might know Optimizely has an integration where you can create and edit pages in the CMS directly from the CMP. One of the benefits of this i...

Marcus Hoffmann | Jul 10, 2024

GetNextSegment with empty Remaining causing fuzzes

Optimizely CMS offers you to create partial routers. This concept allows you display content differently depending on the routed content in the URL...

David Drouin-Prince | Jul 8, 2024 | Syndicated blog

Product Listing Page - using Graph

Optimizely Graph makes it possible to query your data in an advanced way, by using GraphQL. Querying data, using facets and search phrases, is very...

Jonas Bergqvist | Jul 5, 2024