How to get content types

I am developing a Windows application that is negotiating with SharePoint through embedded web services, and I want all types of content to be available on the SharePoint site,

I'm trying to use

Web.Webs WebsService = new Web.Webs (); WebsService.Credentials = credentials; WebsService.Url = "Web Service URL"; XmlNode listOfContentTypes = WebsService.GetContentTypes ();

If the credentials have administrator rights, I can get a list of all available content types. But if the credentials do not have administrator rights, exception 401 is generated (there is not enough permission).

My question is:
How can I get all types of content on a SharePoint site if I do not have administrator privileges?

+3
source share
3 answers

If you want to use OOB web services, you will need to provide credentials (which have sufficient rights) in the calling application.

        Web.Webs WebService = new Web.Webs();
        WebService.Credentials = new NetworkCredential("username", "password");
        XmlNode list = WebService.GetContentTypes();

How you get these credentials is up to you ...

+1
source

I did some reflection in Reflector to find out which permissions are really needed. Check out the method below, which is in the call chain from the service method GetContentTypes():

public string GetContentTypeTemplates()
{
    SPWeb web = SPContext.GetContext(HttpContext.Current).Web;
    web.CheckPermissions(SPBasePermissions.EmptyMask | SPBasePermissions.ManageLists);
    web.CheckPermissions(SPBasePermissions.EmptyMask | SPBasePermissions.AddAndCustomizePages);
    return this.GetGeneralContentTypes(web.AvailableContentTypes);
}

From this we can gather that SharePoint requires you to have permission ManageListsand AddAndCustomizePagesfor all content types.

, , , , , , .

+2

- , - Webs ( SharePoint) . SharePoint.

.

0

Source: https://habr.com/ru/post/1741930/


All Articles