File upload in XForm

by: Jacob Khan

Hello,

My name is Jacob Khan and I am the newly employed rookie researcher at EPiServer. One of my first projects was building a small EPiServer site in order to learn more about the partner experience of EPiServer. One feature of the site was that visitors could apply for jobs by typing in information in fields and uploading a résumé. The current XForm editor does not support files to be uploaded and after having read Allans blog building a new editor did not seem realistic. Instead of only using a simple form I decided to use both an XForm and ASP file upload. By doing this the user can see both information in EPiServer as form data and the file uploaded on the server. I first specified the XForm in the Xform editor. All the information was shown from a placeable unit much like the template. In the XForm no send button was added, instead asp:fileupload and asp:button controls were used.

 

In the markup I first added the XForm control and then the asp controls

 <xforms:xformcontrol ID="FormControl" runat="server" EnableClientScript="true" /> 

<table><tr>

<td><asp:Label runat="server" Text="File:"></asp:Label></td>

<td><asp:FileUpload runat="server" EnableViewState="false" id="file1”/></td>

                       </tr> <tr><td></td>

<td><asp:Button CssClass="button" runat="server" OnClick="buttonSubmit" EnableViewState="false" Text="Send" ID="submit" /></td>

 In the code behind we now specify a function called buttonSubmit

 protected void buttonSubmit(object sender, System.EventArgs e)

        {

                      string path = Server.MapPath(EPiServer.Configuration.Settings.Instance.SiteUrl.LocalPath + "Cv/"); 

                try {

                    File1.SaveAs(path + file2.FileName + FormControl.Data.FormId);

                }

                catch (Exception)                {

                    PostedMessage.Visible = true;

                    PostedMessage.Text = "Unable to save";

                }     

 FormControl.SubmitForm(ChannelOptions.Database);

        }

 

The form data is now visible in EPiServer, except for the file which is in a separate folder on the server named CV.

13 June 2008


Comments

  1. Welcome to the blogging-sphere Jacob. Good post! An alternative solution could be to change a couple of your lines to save the loaded file in the Unified File system / Virtual Path Providers - that would avoid the need for write permissions to the "cv" folder.
  2. Great alternative
  3. Is there a way to use the asp.net web controls to validate the fileupload control together with Xforms validation? It seems like EPiServers validationsummary will only show Xforms validation or web control validation, not together.
  4. Hi Gustaf Try writing your question in our developer forum where you can get better feedback. EPiServer World
  5. Doesn't episerver support the standard XForms file upload?
  6. Based on the sample above, is there a way to also store the uploaded file name in the database when the form is submitted? When I view the FormData tab, it only displays the form and not the file name for the custom uploaded file.
  7. Hi Jacob, Nice Post. If we want to modify some contents already posted by XForm ,then how do you achieve it? Regards, S.K. SreeRaghavendra
  8. Check out this blog http://blog.juszczyk.biz/2008/05/get-posted-data-xformdata-from-xform/
Post a comment    
User verification Image for user verification  
Jacob Khan

About me

I am a researcher at EPiServer based in Stockholm. I started working in the Research department in May 2008.
I also blog on world.episerver.com
See my profile card on world

 

Syndications


Archive


Tag cloud

EPiTrace logger