1
How to get File Path in FileManagerUploading event?
Question asked by Nitin Patil - December 8, 2014 at 1:34 PM
Answered
Hi,
 
I am trying to get file path while uploading a file. In FileManagerUploading event I can get file name only, but not able to get full file path.
 
Can you please help?
 
Thanks,
Nitin

4 Replies

Reply to Thread
0
Cem Alacayir Replied
December 8, 2014 at 2:02 PM
Employee Post
Hi,
You can do it like this:
 
private static void FileManagerUploading(object sender, FileManagerUploadingEventArgs e)
{
    foreach (var validation in e.Validations)
    {
        var filePath = System.IO.Path.Combine(e.Folder.PhysicalPath, validation.Name);
    }
}
 
0
Steve Replied
March 4, 2015 at 10:33 AM
Cem,
 
I just updated to version FileUltimate v4.3.0.2 and noticed the e.Folder.PhysicalPath property is no longer availabile.  I am using this property in all of the FileUltimate events for logging purposes.  I assume the new method uses the AlphaFS library.  How can I get the windows system path? I need it in the same format that I used for the RootFolder.Location (ie: \\server\share)
var filePath = System.IO.Path.Combine(e.Folder.PhysicalPath, validation.Name)
Thanks,
Steve
0
Cem Alacayir Replied
March 4, 2015 at 11:15 AM
Employee Post
Hi Steve,
Yes, PhysicalPath had to disappear because we abstracted the file system. For example, the passed folder may be in a database in the future so PhysicalPath is meaningless for that kind of file system.
However it’s still possible to find out that value considering you already know you are using a physical file system. Just cast it like this:
 
string physicalPath;
using (var fileSystem = (AlphaPhysicalFileSystem)folder.GetFileSystem())
    physicalPath = fileSystem.PhysicalPath;
The using block is required because IFileSystem is disposable, for example if you specified username & password for RootFolder.Location, impersonation will happen and the file system should be disposed to rollback impersonation. If you don't use credentials for your root folders, then you can use this simpler version:
 
var physicalPath = ((AlphaPhysicalFileSystem)folder.GetFileSystem()).PhysicalPath
Note that in partial-trust hosting, you would need to cast to PhysicalFileSystem instead of AlphaPhysicalFileSystem because in that case AlphaFS (long path support) will not be available and regular Sytem.IO will be used.
 
We are still improving this new API, so some minor changes can be made again. Maybe we can add PhysicalPath property back and return non-empty string only when it's possible for easier access.
0
Cem Alacayir Replied
April 1, 2015 at 4:36 PM
Employee Post
FYI, as of latest version (v4.4), you can again easily access the physical path like this in your event handler:
 
e.FileSystem.PhysicalPath
 
The FileSystem property of the event is new and it represents the already opened file system. So you no longer need to call e.folder.GetFileSystem() method and you no longer need to cast to a specific file system.

Reply to Thread