I'am trying to retrieve all site and subsite in sharepoint but i get access denied.
I read about to use GetSubwebsForCurrentUser() property, but i get the same message.
My code is the next
foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications)
{
foreach (SPSite siteCollection in webApp.Sites)
{
foreach(SPWeb web in siteCollection.RootWeb.GetSubwebsForCurrentUser())
{
dropDownSite.Items.Add(web.Url);
}
}
}
please i need help! Thanks!
Organizations use Microsoft SharePoint to create websites. You can use it as a secure place to store, organize, share, and access information from any device. All you need is a web browser, such as Microsoft Edge, Internet Explorer, Chrome, or Firefox.
The URL https://domain-my.sharepoint.com is SharePoint Online My Site host. It's related to users' OneDrive for Business libraries. When user log in this URL, they will be redirected to their OneDrive for Business libraries.
Microsoft SharePoint is a cloud-based service that helps organizations share and manage content, knowledge, and applications to: Empower teamwork.
The SharePoint Framework (SPFx) is a page and web part model that provides full support for client-side SharePoint development, easy integration with SharePoint data, and support for open source tooling.
You will probably need to call SPSecurity.RunWithElevatedPrivileges(delegate())
You could do an inline delegate if you wish, something like:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications)
{
foreach (SPSite siteCollection in webApp.Sites)
{
foreach(SPWeb web in siteCollection.RootWeb.GetSubwebsForCurrentUser())
{
dropDownSite.Items.Add(web.Url);
}
}
}
});
Just to make sure, is this code running on the server that is hosting the Sharepoint portal? What version of Sharepoint are you running?
Also, would it make sense to use the Webservices that Sharepoint exposes? http://msdn.microsoft.com/en-us/library/aa979690(v=office.12).aspx
If you are running this code on the same server as SP, then make sure that your credentials have access to SP. If you are calling this from a website, also make sure that you are not running as "Anonymous".
Over all, I think taking advantage of the webservices is the easiest way to get it working. But make sure that you have the right permissions being sent and that that user has access (in the SP configurations) to that data.
Hope that helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With