File upload in XForm
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