Retreive Unified File System File Path

Vote:
 
Hi. I am using Unified File System to store files in EPiServer. I also want to use a 3rd party program called FastSend to send files i have stored in the file archive. To do this i have to retrieve the full file path to the files stored in the file archive, not the url, but the physical file path. How do get this using Unified File System? BR, Tore
#12835
Nov 16, 2006 15:55
Vote:
 
I'm also interested in this. Anyone have a nice solution? Thanks /Tobias
#14964
Nov 17, 2006 11:25
Vote:
 
Try this: UnifiedFile file = UnifiedFile.Get("/upload/myfile.txt"); string path = Server.MapPath(file.Path);
#14965
Nov 17, 2006 12:54
Vote:
 
Thanks René, but unfortunally it didn't work (for me anyway).
#14966
Nov 17, 2006 13:00
Vote:
 
This depends on the file system. If this is a path located under the siteroot (as /upload does by default), it should work. If it is a versioned file system for an example, the file does not exist on disk with the name you see in the file explorer in EPiServer. To complicate things even more, the file might not exist on disk at all. It might be stored in a database, in SharePoint or somewhere else if you've created your own virtual file system. To make sure you do this 100% correct, you actually need to stream the file to disk (if FastSend cannot accept the file as a stream), and then do a MapPath on that. For the virtual file systems that store the file outside of the webroot - but on disk, you could find the root of the virtual file system beeing used, and use that with the relative path of the file, and find the physical path to the file on disk. /Steve
#14967
Nov 17, 2006 16:11
Vote:
 
Hi Steve. Thank you for your answer. Do have an example on this matter? I am using the virtual file systems that store the file outside of the webroot, but on the harddisk. Could I use the GetFile on the relative path, and by that getting the physical path of the file? BR, Tore Gjerdrum
#14968
Nov 19, 2006 13:30
Vote:
 
The GetFile only give you the UnifiedFile instance, which does not have that information directly (that would break the Unified File System (UFS) architecture :-) ) The underlying provider does however have this (the NativeFile) in your case. For a database provider this will (as I've said before) not work, as the file probably will never hit the server hard drive on the way to the client, everything will happen in memory. As a side effect of the architecture, and the very notion that everything is virtual, that the files being downloaded might never be stored on disk - led to a rather nasty problem. Downloading several BIG files simultaneously would consume large amounts of memory in you asp.net process as the file would be loaded into memory and then streamed to the client. To get around this, the UFS architect added an interface called IFastFileDownload, which the different file providers could implement. It has one method: 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
#14969
Nov 19, 2006 18:13
Vote:
 
Thanks Steve! Works perfect. /Tobias
#14970
Nov 20, 2006 8:24
Vote:
 
Hi Steve. Thank you! Works great!! /Tore
#14971
Nov 20, 2006 11:12
* 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.