ArcGIS Runtime SDK for .NET

Share a portal item

When one of your users creates a portal item and adds it to a portal, using ArcGIS Online or this ArcGIS Runtime API, the item is private by default. Only the owner of the item (and the organization's administrators) are able to view it. This level of sharing is indicated by the portal item's access property.

var isPrivate = (portalItem.Access == PortalAccess.Private);
Caution:

Methods for getting or updating sharing information are only available to the portal item's owner and administrators of the organization. Calling these methods as an unauthorized user will result in an exception.

The access property indicates the item's highest level of sharing. So if the portal item has an access value of:

  • Private—The item is not be shared with anybody. Only the owner and administrator can view the item.
  • Public—The item can be viewed by everybody.
  • Organization—The item can be viewed by every member of the organization that the item is created in.
  • Shared—The item can only be viewed by members of a group that the item is shared with.

You can allow users to change this level of sharing so that the portal item is available to the right users.

Share with everyone or a portal's organization

If you want your portal item to be accessible to everyone, you need to make it public. Any user who has access to the portal website can then find and use the portal item. To make a portal item public, call the ShareWithAsync method and pass true for the everyone argument.

// Share the portal item with the entire organization, or with everyone
await portalItem.ShareWithAsync(withEveryone, withOrganization);
Console.WriteLine("Sharing for " + portalItem.Title + " has been updated.");

To ensure only members of the user's portal have access to an item, you can share it with just the user's portal organization. To do this, pass true for the organization parameter of the ShareWithAsync method.

// Share the portal item with the entire organization, or with everyone
await portalItem.ShareWithAsync(withEveryone, withOrganization);
Console.WriteLine("Sharing for " + portalItem.Title + " has been updated.");

Share with a portal group

If a user is a member of a group, they can share items that they own with that group. Sharing items with specific groups restricts access to a smaller, more focused set of people. For details on portal groups, seeWhat is a group?. The following sections describe how to:

  • Find the groups that the portal item belongs to
  • Find the groups the user is a member of
  • Share a portal item with a group
  • Unshared a portal item from a group

Find a portal item's groups

You can determine which groups a portal item is currently shared with by calling the GetGroupsAsync method on the portal item. This asynchronous method returns three types of groups. In this example:

  • adminGroups contains the groups which the current user is an administrator of.
  • memberGroups contains the groups in which the user is a member.
  • otherGroups contains the public groups or groups that are shared to the user's organization but that the user is not a member of.

This code displays the title of the groups that the item is shared with.

// Get the groups that have access to this item
var itemGroups = await portalItem.GetGroupsAsync();
var adminGroups = itemGroups.Admins;
var memberGroups = itemGroups.Members;
var otherGroups = itemGroups.Others;
// Report the user's role in each group
var sb = new StringBuilder();
sb.AppendLine("Groups for this item");
// Admin
sb.AppendLine("You are an admin in these groups:");
foreach(var group in adminGroups)
{
    sb.AppendLine("- " + group.Title);
}
// Member
sb.AppendLine("You are a member of these groups:");
foreach (var group in memberGroups)
{
    sb.AppendLine("- " + group.Title);
}
// Public group, not a member
sb.AppendLine("You have access to these groups:");
foreach (var group in otherGroups)
{
    sb.AppendLine("- " + group.Title);
}


Debug.Print(sb.ToString());

Share a portal item with specific groups

To share a portal item with specific groups, first determine which groups it should be shared with. For example, you can determine which groups the current user is a member of by iterating through the groups returned from the PortalUser.Groups property as follows:

// Get all groups to which the current user belongs
var usersGroups = myPortal.User.Groups;
// Loop through all the user's groups
foreach(var g in usersGroups)
{
    // Show the title (name) of each group 
    Console.WriteLine(g.Title);
}

Note that some groups are view-only; that is, members can view the items already in the group, but cannot share other items with that group. To learn more about users and groups, see Access content and Access the ArcGIS Platform.

Then to share the portal item with those groups, pass a list of these groups to the ShareWithGroupsAsync method as follows:

// Share the portal item with specified groups (using an enumeration of GroupInfo)
await portalItem.ShareWithGroupsAsync(groupIdList);
Console.WriteLine(portalItem.Title + " is now shared with the selected groups.");

If there is a problem sharing the portal item with some groups, the failures will be indicated in the values returned from the ShareWithGroupsAsync method.

Unshare a portal item from specific groups

To stop sharing a portal item with specific groups pass a list of these groups to the UnshareGroupsAsync method as follows:

// Unshare the portal item with a list of groups 
// Query for all groups owned by Ted Bell
PortalQueryParameters groupQueryParams = new PortalQueryParameters("owner:(\"Ted_Bell\")");
PortalQueryResultSet<PortalGroup> portalGroups = await myPortal.FindGroupsAsync(groupQueryParams);


// Unshare the portal item with all the groups in the results
await portalItem.UnshareGroupsAsync(portalGroups.Results);
Console.WriteLine("No longer sharing " + portalItem.Title + " with Ted's group(s).");

Stop sharing

To stop sharing the item, call the UnshareAsync method. Calling this method:

  • Makes the item private and accessible to only the item owner (and the organization's administrator)
  • Removes all groups from the item's groups list

// Unshare item from all groups with which the item is currently being shared
await portalItem.UnshareAsync();


// Set sharing to false for the organization and for everyone
await portalItem.ShareWithAsync(false, false);

Related topics