citrix / ShareFile-NET

C# library for accessing ShareFile V3 API
MIT License
36 stars 26 forks source link

Navigate to File or Folder given Path #12

Open alexandrugheorghiu opened 9 years ago

alexandrugheorghiu commented 9 years ago

How would one go about obtaining the ShareFile.Api.Models.File or the ShareFile.Api.Models.Folder given a path?

E.g., the path can be:

  1. "My Files & Folders/Sample Folder/Sample Sub Folder"
  2. "My Files & Folders/Sample Folder/Sample Sub Folder/default.file"
  3. "Shared Folders/Sample Shared Folder/Sample Shared Sub Folder"
  4. "Shared Folders/Sample Shared Folder/Sample Shared Sub Folder/defaultShared.file"

For now, personally I'm using:

var folder = (ShareFileFolder)await sfClient.Items.Get().Expand("Children").ExecuteAsync();

to get the default folder, or:

var allSharedAlias = sfClient.Items.GetAlias("allshared");
var sharedFolder = await sfClient.Items.Get(allSharedAlias).Expand("Children").ExecuteAsync();
var folder = (ShareFileFolder)await sfClient.Items.Get(sharedFolder.url).Expand("Children").ExecuteAsync();

to get the shared folder. And from there, I'm recursively navigating from one path element to another, until the desired leaf.

Is there another simpler/faster way that's supported by the SDK?

rgmills commented 9 years ago

Yep!

Here is the API documentation around that: http://api.sharefile.com/rest/docs/resource.aspx?name=Items#Get_Item_By_Path

With the .NET SDK, it should be something along these lines

var folder = await sfClient.Items.ByPath("/My Files & Folders/Subfolder 1").ExecuteAsync()

alexandrugheorghiu commented 9 years ago

Great! Thanks.

alexandrugheorghiu commented 9 years ago

I've tested this and it works great for files & folders from My Files & Folders directory. However, it doesn't seem to be working when the root is Shared Folders.

E.g.:

var folder = await sfClient.Items.ByPath("/Shared Folders/Subfolder 1").ExecuteAsync();

throws an ODataException: Item: Path element 'Shared Folders' not found. (HttpStatusCode: NotFound).

I've also tried:

var allSharedAlias = sfClient.Items.GetAlias("allshared");
var sharedFolder = await sfClient.Items.Get(allSharedAlias).Expand("Children").ExecuteAsync();
var folder = await sfClient.Items.ByPath(sharedFolder.url, "/Subfolder 1").ExecuteAsync();

but with the same result/exception.

Any insights on how to obtain the files & folders from the Shared Folders, by path?

rgmills commented 9 years ago

@alexandrugheorghiu Let me debug on our side and see what we're doing wrong with respect to handling allshared - allshared itself is kind of weird since it's a projection of folders where we may elevate passthrough folders to surface a folder that you can actually do something in.

E.g.:

Folder 1 may show up as a child of allshared, however if you look at Path it may be:

/root/[accountId]/fo1c96de-4b6a-42ce-b083-695d23982da2/fo6df679-549e-486c-ab3e-c0fee8e2552d

Which implies that you have what we call passthrough records for fo1c96de-4b6a-42ce-b083-695d23982da2 and fo6df679-549e-486c-ab3e-c0fee8e2552d which indicate you have no permissions on the folder, but can view it to access a folder beneath.

While Folder A would have a path of:

/root/[accountId]

If Subfolder 1 is indeed a root level folder, here is a workaround until we figure out how best to handle allshared:

var folder = await sfClient.Items.ByPath("/Subfolder 1").ExecuteAsync();
alexandrugheorghiu commented 9 years ago

@rgmills the suggested workaround seems to be working (on initial testing) - thanks. Looking forward to a solid solution for handling allshared.

bradvido commented 7 years ago

I'm using the same workaround today (2 years later). Is this still acceptable? Is there a more standard way to access Shared Folders by their path?