tags:

views:

252

answers:

3

Hi,
We are impersonating a SharePoint User and trying to acces a list item.

using (SPSite site = new SPSite(BAH.SN.Properties.Settings.Default.RootSiteUrl, new SPUserToken(currentUser.ImpersonationToken)))
        {
            using (SPWeb web = site.RootWeb)
            {
                SPList list = web.GetList(BAH.SN.Properties.Settings.Default.CommunitiesListPath);
                if (list != null)
                {
                    SPQuery query = CAMLHelper.GetSPQueryForCommunityListByOwner(user.UserName);
                    SPListItemCollection items = list.GetItems(query);
                    if (items != null && items.Count > 0)
                    {
                        // Read here
                    }
                }
            }
        }

We are able to get a handle on the list, but as soon as we try to access any property of SPListItemCollection "items", we get a COM exception: 532459699.

We are running FBA and the user calling this code is an anonymous user.

Kind regards,

A: 

Hi,

have you tried using ElevatedPrivileges instead of a token?

SPSecurity.RunWithElevatedPrivileges(delegate() {

//your code inside here, except use the SPSite ctor that only takes the url and get that frome SPContext:
// new SPSite(SPContext.Current.Site.Url);

}

Also please provide full stack trace to give us the best way to help you. If you dont know how to enable that in web.config, check one of the many blog posts on that issue: http://blogs.importchaos.com/alonsorobles/2008/06/09/enabling-the-sharepoint-safe-mode-call-stack-disabling-custom-errors-and-enabling-compilation-debugging/

Anders Rask
A: 

SPSecurity.RunWithElevatedPrivileges will run the code in the System Account.That wont solve his/er issue

Kusek
A: 

Try using System Token.

using (SPSite site = new SPSite(BAH.SN.Properties.Settings.Default.RootSiteUrl, SPContext.Current.Site.SystemAccount.UserToken))
{ 
}
Gulia