Does anyone have a straightforward exampel or knowledge of a tutorial on image upload and associating the uploaded image with an Image-property?
I've browsed several examples on how to use virtual directories in EPiServer but I can't seem to get it to work.
Basically, this is what I want to do:
This code is used as part of the iPhone image upload but it shows how to upload an image to a VPP folder:
string virtualDir = "/Global/iPhoneUploadedImages/";
UnifiedDirectory directory = HostingEnvironment.VirtualPathProvider.GetDirectory(virtualDir) as UnifiedDirectory;
directory.BypassAccessCheck = true;
byte fileBytes = this.fu.FileBytes;
if (directory.GetFiles().Length > 0)
file = directory.GetFiles();
file = directory.CreateFile("tmpiPhoneImage.png");
Stream stream = file.Open(FileMode.Create);
int length = fileBytes.Length;
stream.Write(fileBytes, 0, fileBytes.Length);
directory.BypassAccessCheck = false;
Obviously there is the associated aspx to go with this:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ImageUpload.aspx.cs" Inherits="EPiServer.Research.iPhone.ImageUpload" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<form id="form1" runat="server">
<asp:FileUpload runat="server" ID="fu" EnableViewState="false" />
<asp:Button ID="Submit" runat="server" />
You can replace the global VPP folder reference with one to the page files VPP folder and this should cover your needs?
If you want to know how to create a page programmatically I'd suggest you look at the EPiServer SDK documentation at http://sdk.episerver.com