Question

I've searched but am unable to find my specific question. I am wondering if I will have the ability to give a user contribute permission to a list and then remove it after writing to that list. My goal is to have a program that the user will be using based on their own log in credentials that will then save their responses to a SharePoint 2007 list that they will, hopefully, never have access. They should also not know this process is taking place. So essentially it will be like they are giving themselves permission to a list and then removing it. My best bet that I've found so far is to have the program log into SharePoint under my credentials and then give permissions but that would mean I would have to hard code my credentials which I would like to avoid if possible. Any answer is definitely appreciated! I am using Visual Studio 2010 and programming in C#, Visual Basic is also OK.

Était-ce utile?

La solution

You can use SPSecurity.RunWithElevatedPrivileges:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite site = new SPSite(web.Site.ID))
    {
    // implementation details omitted
    }
});

That way you don't need to add and remove permissions and can execute code in the context of the application pool account.

SPSecurity.RunWithElevatedPrivileges

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top