London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
AI OnAI Off
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
UnifiedFile file = UnifiedFile.Get("/upload/myfile.txt");
string path = Server.MapPath(file.Path);
string GetFullPath();
By having the full path to the file on disk, EPiServer can hand over the streaming task to IIS, which is much more efficient, and will not consume large chunks of memory. IIS will stream the file in blocks, and in contrast, will only have to allocate a small amount of memory for each block.
Fortunately, this interface is exactly what you need. As your initial task is to offload the download of large files to another process, you should make sure that the ASP.NET process never needs to load these into memory. By looking for this interface, you actually accomplish both tasks (getting the physical path, and ensuring no one puts large files in non-physical file systems.)
On to the code:
string path = "/demo/myfolder/mytext.txt";
UnifiedFile file = UnifiedFileSystem.GetFile(path);
IFastFileDownload filedownload = (IFastFileDownload)file.Provider;
string physicalPath = filedownload.GetFullPath();
Response.Write("Path is: " + physicalPath + "
");
will display:
Path is: C:\Inetpub\FileSystem\demo\myfolder\mytext.txt
on my box.
/Steve