About Me

My photo
a Dynamic and Energetic guy.....

Monday, March 17, 2014

SharePoint User Token Code

try
            {
                SPSite tempSite = new SPSite(siteURL);
                string loginNameInFull = @"i:0#.w|" + username;
                SPUserToken userToken = tempSite.OpenWeb().AllUsers[loginNameInFull].UserToken;
                using (SPSite site = new SPSite(siteURL, userToken))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList olist = web.Lists[listName];
                        SPListItemCollection ocol = olist.Items;
                        return ocol;
                    }
                }
            }

This is passing credentials to Windows Authentication
UserName append with "i:0#w|" 


No comments:

My Masters