protected void btnSharingStatus_Click(object sender, EventArgs e)
        {
            // Get full URL to the document
            if (documents.Items.Count > 0)
            {
                var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
                using (var ctx = spContext.CreateUserClientContextForSPHost())
                {
                    // Get file link URL
                    string fileUrl = ResolveShareUrl(ctx, documents.SelectedValue);

                    // Get current sharing settings
                    ObjectSharingSettings result = ctx.Web.GetObjectSharingSettingsForDocument(fileUrl, true);

                    // For outputting the list of people site is being shared
                    if (result.ObjectSharingInformation.SharedWithUsersCollection.Count > 0)
                    {
                        string userList = "";
                        foreach (var item in result.ObjectSharingInformation.SharedWithUsersCollection)
                        {
                            userList += string.Format(" - {0}", item.Email);
                        }
                        lblStatus.Text = string.Format("Document shared with: {0}", userList);
                    }
                    else
                    {
                        lblStatus.Text = string.Format("Document not shared with anyone");
                    }
                }
            }
            else
            {
                lblStatus.Text = "No document selected to be unshared.";
            }
        }
Ejemplo n.º 2
0
        protected void btnSharingStatus_Click(object sender, EventArgs e)
        {
            var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

            using (var ctx = spContext.CreateUserClientContextForSPHost())
            {
                // Get object sharing setting configuration from the site level
                ObjectSharingSettings result = ctx.Web.GetObjectSharingSettingsForSite();

                // For outputting the list of people site is being shared
                if (result.ObjectSharingInformation.SharedWithUsersCollection.Count > 0)
                {
                    string userList = "";
                    foreach (var item in result.ObjectSharingInformation.SharedWithUsersCollection)
                    {
                        userList += string.Format(" - {0}", item.Email);
                    }
                    lblStatus.Text = string.Format("Site shared with: {0}", userList);
                }
                else
                {
                    lblStatus.Text = string.Format("Site not shared with anyone");
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get current sharing settings for document and load list of users it has been shared automatically.
        /// </summary>
        /// <param name="web">Web for the context</param>
        /// <param name="urlToDocument"></param>
        /// <param name="useSimplifiedPolicies"></param>
        /// <returns></returns>
        public static ObjectSharingSettings GetObjectSharingSettingsForDocument(this Web web, string urlToDocument, bool useSimplifiedPolicies = true)
        {
            // Group value for this query is always 0.
            ObjectSharingSettings info =
                Microsoft.SharePoint.Client.Web.GetObjectSharingSettings(web.Context, urlToDocument, 0, useSimplifiedPolicies);

            web.Context.Load(info);
            web.Context.Load(info.ObjectSharingInformation);
            web.Context.Load(info.ObjectSharingInformation.SharedWithUsersCollection);
            web.Context.ExecuteQueryRetry();

            return(info);
        }
Ejemplo n.º 4
0
        private static async Task <ObjectSharingSettings> GetObjectSharingSettingsForSiteImplementation(Web web, bool useSimplifiedPolicies)
        {
            // Ensure that URL exists
            if (!web.IsObjectPropertyInstantiated("Url"))
            {
                web.Context.Load(web, w => w.Url);
                await web.Context.ExecuteQueryRetryAsync();
            }

            ObjectSharingSettings info = Web.GetObjectSharingSettings(web.Context, web.Url, 0, useSimplifiedPolicies);

            web.Context.Load(info);
            web.Context.Load(info.ObjectSharingInformation);
            web.Context.Load(info.ObjectSharingInformation.SharedWithUsersCollection);
            await web.Context.ExecuteQueryRetryAsync();

            return(info);
        }
        /// <summary>
        /// Get current sharing settings for site and load list of users it has been shared automatically.
        /// </summary>
        /// <param name="web">Web for the context</param>
        /// <param name="useSimplifiedPolicies"></param>
        /// <returns></returns>
        public static ObjectSharingSettings GetObjectSharingSettingsForSite(this Web web, bool useSimplifiedPolicies = true)
        {
            // Ensure that URL exists
            if (!web.IsObjectPropertyInstantiated("Url"))
            {
                web.Context.Load(web, w => w.Url);
                web.Context.ExecuteQueryRetry();
            }

            ObjectSharingSettings info = Web.GetObjectSharingSettings(web.Context, web.Url, 0, useSimplifiedPolicies);

            web.Context.Load(info);
            web.Context.Load(info.ObjectSharingInformation);
            web.Context.Load(info.ObjectSharingInformation.SharedWithUsersCollection);
            web.Context.ExecuteQueryRetry();

            return(info);
        }