How to get Folder ID from portal In ArcGis Pro SKD?

251
1
10-17-2017 11:26 AM
Highlighted
Occasional Contributor II

Using the ArcGIS Pro 2.0(1) how can I check if  a specific folder in my content exists, create it if not, and obtain its ID.

During publishing a Web Layer, I need as an optional parameter the FolderID - not the name!

new EsriHttpClient().Upload(portal.PortalUri.ToString(), layerItem, "my Layer Name", new[] {"myTag"}, "folderID");

Reply
0 Kudos
1 Reply
Highlighted
Esri Contributor

At 2.1, call portal.GetUserContentAsync

var owner = portal.GetSignOnUsername();

var userContent = await portal.GetUserContentAsync(owner);

foreach (var pf in userContent.PortalFolders)

    System.Diagnostics.Debug.WriteLine($"{pf.Name},{pf.FolderID}");

At 2.0, you have to execute the rest query directly for user content (via EsriHttpClient). The url would look like this:

var owner = portal.GetSignOnUsername();

var url = $"{portal.PortalUri.AbsoluteUri}/content/users/{owner}";

var response = new EsriHttpClient().Get(url);

var json = await response.Content.ReadAsStringAsync();

The returned json will contain your folders. See Rest API User Content