Using the Clientfilesystem, (or other), is there a way to get the full path and name of the file?
If so, how?
Thanks
The shared folder is the folder that the user shares with the web application via the Client File System API. This is the folder that the user chooses from the dialog when you call this code:
Directory directory = await ClientFileSystem.ShowDirectoryPickerAsync();
I’ve created an example directory that looks like this:
Example Folder
-folder1
—-file1.txt
—-file2.txt
-folder2
-textfile.txt
To get the relative path, you can use the “Name” property for each of the files and folders, then put it all together. For example here’s how to get the relative path to file1.txt from the root folder (Example Folder):
Directory directory = await ClientFileSystem.ShowDirectoryPickerAsync();
//get all subdirectories, in this case folder1 and folder2
Directory[] subDirectoryArray = await directory.GetDirectoriesAsync("*");
//get folder1-it's the first one in the array
Directory folder1 = subDirectoryArray[0];
//get file1.txt from folder1
File[] fileArray = await folder1.GetFilesAsync("file1.txt");
//get the first (and only) file from the array
File file = fileArray[0];
//Put together the filepath based on the Name property
AlertBox.Show("filepath: "+folder1.Name+"\\"+file.Name);
I’ve attached the sample project and the sample directory.
Download both, and when you run the sample project, after clicking the button, select the sample directory (Example Folder). Doesn’t matter where you put it in your filesystem as the browser will only have access to the files within the sample directory.
See also:
https://docs.wisej.com/extensions/extensions/clientfilesystem
https://developer.mozilla.org/en-US/docs/Web/API/File_API
Thanks Julie,
I don’t understand “within the shared folder”, what is the shared folder…?
Unfortunately, it’s not possible due to browser security restrictions. You can only get the relative path within the shared folder.
Julie
Please login first to submit.