views:

197

answers:

3

Hi,

I'm developing a windows application, that talks to SharePoint via its built in web services, and i want to get all content types available on a SharePoint site,

I'm trying to use

Web.Webs WebsService = new Web.Webs(); WebsService.Credentials=credentials; WebsService.Url="url of the web service"; XmlNode listOfContentTypes = WebsService.GetContentTypes();

If credentials have administrator privileges i can get the list of all the content types available, But if credentials don't have administrator privileges a 401 exception is thrown (not enought permission).

My question is:
How can i get all content types available on a SharePoint site if i don't have administrator priviliges?

A: 

You could write a wrapper web service that calls the Webs webservice (or even use the SharePoint object model) with the required credentials. This wrapper service could be deployed to the SharePoint server.

Your custom application could then call the wrapper service without needing to provide the correct credentials.

Paul Lucas
I need to do it with sharepoint built in web sercvices. Can i get the content types without writing a custom web service?
Gaby
Yep, see other answer
Paul Lucas
A: 

If you wish to use the OOB web services, then you will need to provide the credentials (that have sufficient rights) in your calling application.

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

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

Paul Lucas
I have a form that users fill in the username domain and password, then i'm getting the content type id (that i will use it to query for all items that have this content type) from an xml file located in a shared location where i can't modify it, and to build this query i need to know the name of the content type from his id.How can a user with only read privileges to know the name of the content type from his web id? In object model the problem is resolved by using SpSecurity.RunWithelevatedprivilege..., what should i have to do in web services? is it possible to get the web content types?
Gaby
There isn't an equivalent for SPSecurity.RunWithElevatedPrivileges when it comes to the web services, and for good reason. If there were, anyone could write a program that could execute code against a SharePoint server as an administrator without having physical access to the server. It would be a pretty serious security hole.
Paul Lucas
+1  A: 

I did some poking around in Reflector to see what permissions are actually required. Check out the method below, which is down the call chain from the GetContentTypes() service method:

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 that you have ManageLists and AddAndCustomizePages permissions to retrieve all content types.

So, one solution for you could be to ensure that the client account has these permissions, perhaps by creating a custom permission level or, if working within a publishing site, adding the account to the Designers group.

kbrimington