Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Save Target As for Video Files in a VPP.


Hi Guys,

I'm needing to have the "Save File Dialog" show up when a user clicks on a "Download" button for a video. I've currently got a Download page which expects an ID to then - in code - grab the PageReference of the ID and get the pagedata back and to a link to a virtual path file.

The actual address I get back is "/Documents/folder/folder/". Since I will need to then take the contents of this file and put them in the output stream, I will need to grab the actual file data. Since this file uses the Virtual Path Provider, when I use Server.MapPath() all I get back is it trying to go to my local machine and not the Virtual Path. How can I get back the actual video data in code?


Oct 12, 2009 14:52


 If i've understood you correct you can use this code where "file" is the path to your movie: 

UnifiedFile filePath = HostingEnvironment.VirtualPathProvider.GetFile(file) as UnifiedFile;
if (filePath == null) return;

Stream s = filePath.Open(FileMode.Open, FileAccess.Read);
int len = (int)s.Length;
byte[] buffer = new byte[s.Length];
s.Read(buffer, 0, len);
Response.AppendHeader("content-disposition", "attachment; filename=" + filePath.Name);


Oct 12, 2009 15:27

Beware of that this approach might cause some massive amount of memory to be allocated...consider for example sending a 1Gb videofile which would cause a 1Gb buffer to be allocated...

Now, all this is done for you in the EPiServer.Web.Hosting.WebDownloadManager which has a convenient method: TransmitFile.

You might call it like this:

If the file is hosted on a nativeprovider, the fastes Response.TransmitFile can be used, if not, the file content is streamed in reasonably sized chunks.

It also sets the appropriate content headers for you if you specify the DownloadAction.Download
(i.e. content-disposition: attachment)



Oct 13, 2009 15:16
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.