.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Post New Web Links

How can I get SPGroup name by SPUser?

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :C#

Hi All,

I got an user name, how can I get the group name of the user programmatically?

thank you

View Complete Post

More Related Resource Links

How to create SPUser obj or SPRoleAssignment using the user display name not using login name "domai

Suppose there is a user called "Jake Gittes" with login name "domain\jakeg". Now I want to create either SPUser/SPRoleAssignment object using the user full name ("Jake Gittes"). I tried using SPWeb.AllUsers["Jake Gittes"]. But it is throwing exception.

Cannot Access Certain Members of a Non-Null SPUser

When logged in with certain users and we try to access SPUser.Groups or SPUser.OwnerGroups we are getting an error that redirects us to our custom error page. The odd part is that the SPUser object is not null and even when surrounding these offending statements in try/catch blocks we still receive the error redirect. Here is a code snippet showing one of the member accesses that is causing the error redirect:   SPUser _user =SPControl.GetContextWeb(this.Context).CurrentUser; if (_user == null) { _user = SPContext.Current.Web.EnsureUser("Sharepoint/System"); } if(_user != null) { if(_user.Groups != null) { foreach (SPGroup _userGroup in _user.Groups) { _HiddenDiv.Text += _userGroup.Name.ToString() + ", " ; } } This along with any access of Groups or OwnerGroups will cause a redirect to our custom error page. However, as mentioned above, this is only affecting about half of our user population -- the other half is able to login and have their groups examined properly. As always, please let me know if you have any questions or need some further information. Any help with this is greatly appreciated as I'm not sure I have too many hairs left to pull out of my head ;) -Tim

Create SPUser object using user credentials on claims based site.



I would like to create SPSite object and pass user token as an argument to make sure all operations are executed with SharePoint security trimming. Inside SPSite I am reading some file content using File.OpenBinaryStream() method.

I am not sure if there is a way to create SPUser using user credentials. I am able to get SPUser by getting it from SPWeb.AllUsers collection using user login name. However it doesn't work for claims based sites as login name for these users looks like i:0#.w|domain\username. 

Am I allowed to user code like this:

SPUser user = web.AllUsers["i:0#.w|domain\username"];

to get SPUser object? I know that 'w' from 'i:0#.w' string means that it is Windows user. What do other symbols mean? Is there any method which can generate login name from user credentials so I may use it to get SPUser from AllUsers collection?

Possibly there are some other ways to execute code for SPSite under some SharePoint user privileges?

P.S. All my code is running out of SharePoint context. I have tried to user windows impersonation but got Access Denied error.

Thanks beforehand for any help,


Move-SPUser trouble


Hi @all,

I try to change some usermapping in my SharePoint Foundation Farm with the following command in the powershell:

move-spuser -IgnoreSID -Identity ADD\M45443 -NewAlias ADI\M45443
move-spuser -IgnoreSID -Identity "ADD\M45443" -NewAlias "ADI\M45443"

Unfortunately I get this errormessage:

Move-SPUser : The parameterless Read method can only be used when this instance was initialized with an SPUser object.
At line:1 char:12
+ Move-SPUser <<<<  -Identity "ADD\M45443" -NewAlias "ADI\M45443"
    + CategoryInfo          : InvalidData: (Microsoft.Share...PCmdletMoveUser:
   SPCmdletMoveUser) [Move-SPUser], InvalidOperationException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletMoveUser

Do you have any idea what's wrong with my command?

Thanks in advance


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend