Problem with Sharepoint speed using sharepoint Object Model: get user's group from userID -
i quite stumped this. in enhancing existing feature sharepoint solution, found querying wss_content directly. knowing should not using stored procedure, used sharepoint object model retrieve users group information username. what's burning me is slower stored procedure. there smarter/faster way information? using sharepoint 2007. below function does:
private string gettitle(string username) { string results = string.empty; try { spsite spsite = new spsite("http://devvm"); spweb spweb = spsite.allwebs[""]; spuser user = spweb.allusers["aspnetsqlmembershipprovider:" + username]; spgroupcollection groups = user.groups; results = groups[0].name; } catch (exception ex) { console.writeline("unable find user" + username); results = "no group found"; } return results; }
and stored procedure code is:
select @role=groups.title wss_content.dbo.userinfo info left join wss_content.dbo.groupmembership membership on info.tp_id=membership.memberid left join wss_content.dbo.groups groups on membership.groupid=groups.id tp_login='aspnetsqlmembershipprovider:' + @username
fyi reason have in try-catch sub-query list might not have user associated item. in appreciated.
how calling code? if using inside console application yes slower, needs fire supporting objects live when using inside native sharepoint context.
also referencing spsite , spweb object without disposing of object, has inherent performance issues well.
Comments
Post a Comment