Programatically Check if the logged in user matches with user in a list item

Hi All, 
I have a custom list with 1) title column 2) People column. 
I simple need to check if the logged in user = user in the column 2, and if yes fill a List<> with column 1 value. 
But when comparing, the value in list item is in different format than what we get by user.ToString() 
Following is what I tried: 
SPUser user = oWeb.CurrentUser;
List<String> usergrps = new List<String>();
foreach (SPListItem itemA in GrpSubsItems)
if (itemA["SubscribedBy"].ToString() == user.ToString())
usergrps.Add(itemA["Group"].ToString());
itemA["SubscribedBy"].ToString() gives = 10;#Some Name
where as user.ToString() gives = i:0#.w|domain\user 
Kindly guide if my approach is not correct. Thanks. 
Regards, Nayan

Hi Nayan,
Please modify the code like below:
SPUser user = oWeb.CurrentUser;
List<string> usergrps = new List<string>();
foreach (SPListItem itemA in GrpSubsItems)
string userName = itemA["SubscribedBy"] as string;
SPFieldUserValue userA = new SPFieldUserValue(itemA.ParentList.ParentWeb, userName);
if (userA.LoginName==user.LoginName)
usergrps.Add(itemA["Group"].ToString());
More information:
http://ethan-deng.blogspot.com/2013/03/get-spuser-from-user-column-there-are.html
Best Regards,
Dennis Guo
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected]

Similar Messages

  • Programatically Check if the logged in user is in the Administrators group in Project Server (C#, VS2010)

    Hi I would like to be able to check if the logged in user is a member of the administrator group programatically through c#
    I know that I can get the user's GUID / check if they are actually a user in project server (resource table in reporting DB) but I am having trouble finding out how to programatically check if they are a member of the "Administrators" group.
    Could somebody please provide a code sample of how to check if a user is in the administrators group when you have their GUID or username or name?
    I did not see a table in the reporting DB that has this so I am guessing this has to be done through the PSI..
    Thanks in advance!
    BTW.. i am just wondering is there a way to check each groups permission levels? was wondering that if it is possible, what is the best way to implement a similar security model to that of the actual project server 2010

    hi Amit :) I ended up finding the answer myself before you posted here but thank you for your reply anyways, it is basically the same thing that I did.
    This is what I ended up doing :) Basically I have three different types of users configured in my web.config - admins, readwrite users, and read only users. In my code here I loop through and find out who the person is. Based on what group they are in I
    can later show/hide different options in my application :)
    SvcSecurity.SecurityClient security = new SecurityClient(ENDPOINT_PROJ_SECURITY);
    string adminGroupsString = ConfigurationManager.AppSettings["adminGroups"];
    string readWriteString = ConfigurationManager.AppSettings["readWriteGroups"];
    string readOnlyString = ConfigurationManager.AppSettings["readOnlyGroups"];
    List<string> adminGroups = new List<string>(adminGroupsString.Split(';'));
    List<string> readWriteGroups = new List<string>(readWriteString.Split(';'));
    List<string> readOnlyGroups = new List<string>(readOnlyString.Split(';'));
    List<Guid> adminGroupIDs = new List<Guid>();
    List<Guid> readWriteGroupIDs = new List<Guid>();
    List<Guid> readOnlyGroupIDs = new List<Guid>();
    List<Project> projectList = new List<Project>();
    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["RDB"].ConnectionString);
    con.Open();
    SqlCommand command = new SqlCommand("SELECT * FROM MSP_EpmResource where ResourceNTAccount = @username", con);
    command.Parameters.AddWithValue("@username", this.User.Identity.Name);
    SqlDataReader reader = command.ExecuteReader();
    if (reader.Read())
    string resourceID = reader["ResourceUID"].ToString();
    //Get a list of security groups
    SvcSecurity.SecurityGroupsDataSet sgds = security.ReadGroupList();
    //Get the IDs of the required groups
    foreach (SvcSecurity.SecurityGroupsDataSet.SecurityGroupsRow ds in sgds.SecurityGroups)
    if (adminGroups.Exists(group => ds.WSEC_GRP_NAME == group))
    adminGroupIDs.Add(ds.WSEC_GRP_UID);
    else if (readWriteGroups.Exists(group => ds.WSEC_GRP_NAME == group))
    readWriteGroupIDs.Add(ds.WSEC_GRP_UID);
    else if (readOnlyGroups.Exists(group => ds.WSEC_GRP_NAME == group))
    readOnlyGroupIDs.Add(ds.WSEC_GRP_UID);
    bool isAdmin = false;
    //Go through each group using the id and check if the current
    //user is in that group (for example here check if the user is an admin)
    foreach (Guid id in adminGroupIDs)
    SecurityGroupsDataSet group = security.ReadGroup(id);
    foreach (SvcSecurity.SecurityGroupsDataSet.GroupMembersRow member in group.GroupMembers)
    if (member.RES_UID.ToString().Equals(resourceID))
    isAdmin = true;
    Session["createReport"] = "true";
    break;
    //If the user is not an admin then continue checking who they are
    if (!isAdmin)
    bool readWrite = false;
    //Check if the user is a read write group member
    foreach (Guid id in readWriteGroupIDs)
    SecurityGroupsDataSet group = security.ReadGroup(id);
    foreach (SvcSecurity.SecurityGroupsDataSet.GroupMembersRow member in group.GroupMembers)
    if (member.RES_UID.ToString().Equals(resourceID))
    Session["createReport"] = "true";
    readWrite = true;
    break;
    //If the user is not a read write group member either then check if they are a team member
    if (!readWrite)
    foreach (Guid id in readOnlyGroupIDs)
    SecurityGroupsDataSet group = security.ReadGroup(id);
    foreach (SvcSecurity.SecurityGroupsDataSet.GroupMembersRow member in group.GroupMembers)
    if (member.RES_UID.ToString().Equals(resourceID))
    Session["createReport"] = "false";
    break;
    Cheers! :)

  • Help!  Just did the Update (ML 10.8.4) after receiving a new HD since mine crashed last week, and now my Mac won't let me past the log in screen even with correct password.

    Help!  Just did the Update (ML 10.8.4) after receiving a new HD since mine crashed last week and the shop didn't update it back to Mavricks which I had previously done...and now my Mac won't let me past the log in screen even with correct password entered. It just spins like I'm logging in and then goes back to the user log in screen.  I did the process where I restarted and pressed control S and created a new user and password, but once created same issue and can't get passed that screen.
    Super frustrated and any help is appreciated!

    I have decided to dedicate this thread to the wonderful errors of Lion OSX. Each time I find a huge problem with Lion I will make note of it here.
    Today I discovered a new treasure of doggie poop in Lion. No Save As......
    I repeat. No Save As. In text editor I couldn't save the file with a new extension. I finally accomplished this oh so majorly difficult task (because we all know how difficult it should be to save a file with a new extension) by pressing duplicate and then saving a copy of the file with a new extension. Yet then I had to delete the first copy and send it to trash. And of course then I have to secure empty trash because if I have to do this the rest of my mac's life I will be taking up a quarter of percentage of space with duplicate files. So this is the real reason they got rid of Save As: so that it would garble up some extra GB on the ole hard disk.
    So about 20 minutes of my time were wasted while doing my homework and studying for an exam because I had to look up "how to save a file with a new extension in  mac Lion" and then wasted time sitting here and ranting on this forum until someone over at Apple wakes up from their OSX-coma.
    are you freaking kidding me Apple? I mean REALLY?!!!! who the heck designed this?!!! I want to know. I want his or her name and I want to sit down with them and have a long chat. and then I'd probably splash cold water on their face to wake them up.
    I am starting to believe that Apple is Satan.

  • I'm trying to make a purchase and I get a message that the information does not match with the bank. What can I do?

    I'm trying to make a purchase and I get a message that the information does not match with the bank. What can I do?

    Go to the APP store or Itunes. On the bottom of the mainpage, tap your apple id, view account. Then you can edit the payment information. Or you can do it(if you encounter a problem there) on Itunes on computer. Just go to the store, select your name and edit information. Make sure everything matches...exp date, name as appears on card etc..

  • A PO has posted,goods r received but the invoice is not matching with the..

    hi
    A PO has posted,goods r received but the invoice is not matching with the PO as the TAX was reduced after posting. PLz clarify
    can some explain the issue plz

    Hi,
    1. You are talking about which tax (Is it Excise Duty + CST/VAT) if yes then you can post the Excise invoice with correct duty amount in J1IEX and then same will get defaulted in MIRO as per the duty posted in Excise Invoice not as per PO.
    If you have already posted the  excise invoice then go for cancellation of same in J1IEX and then cancel GR and Post excise invoice to reverse Part 2 entries and then again do GR and Post Excise invoice with correct amount and then do LIV.
    2. If it is only CST / VAT then simply use the appropriate tax code in MIRO as per the revised tax rate.
    For e.g. if in PO Tax code is 4% VAT and now if you get invoice of say 1% VAT from vendor then simply select the tax code of 1% VAT in MIRO similarly can be done in case of CST and Service Tax also. Only in case of Excise duty you have to follow the above method.

  • I'm trying to upload the new itunes version because The older one doesnt match with the iphone 5. At one step it is required one code to allow the installation but as It is not the itunes code which one is it ?

    I'm trying to upload the new itunes version because The older one doesnt match with the iphone 5. At one step it is required one code to allow the installation but as It is not the itunes code which one is it ?

    Hello, GwladysPa. 
    Thank you for visiting Apple Support Communities. 
    I believe that the iTunes update is requesting your computer's administrator password to update the application.  Here is the article that explains this process. 
    Mac OS X: Software installations require administrator password
    http://support.apple.com/kb/HT2558
    Cheers,
    Jason H. 

  • Is there any script available to fetch the logged in time of all users in a computer for a month?

    Hi,
      I have been searching for a script ,that fetch the logged in time of all the users in a particular computer for a month.I couldnt find anything.
    Thanks in advance for quick response.
    Thanks and regards..
    Midhun P s

    Hi,
    I suggest looking here:
    http://gallery.technet.microsoft.com/scriptcenter
    It's highly unlikely that you'll find something pre-written that will meet all of your requirements, but there should be enough in the repository to give you a starting point.
    EDIT: If you're looking for someone to do all the work for you, you can try posting a request here:
    http://gallery.technet.microsoft.com/scriptcenter/site/requests
    I have no idea if anyone ever goes through these requests though (I know I don't).
    Don't retire TechNet! -
    (Don't give up yet - 12,700+ strong and growing)

  • Ipad and Iphone with different apple ID. Changed to same, but can't change the Ipad Icloud to match with the same @me account.  Help!

    When I got my Iphone, I couldn't remember the apple ID, so Best Buy created one.  Now my Ipad Icloud account has a different ID than my Iphone.  Can I change this so all the passwords match?  I was able to log in to the Ipad and change the Apple ID to match the Iphone but can't find a way to do same for Icloud on Ipad.
    thanks

    So are you trying to change your passwords?  Or change which account is logged into icloud?
    Here are the instructions for changing which account is logged into icloud.  Go to settings-icloud-delete account.  Then settings-icloud-sign in with the account you wish to use.

  • In AE CS6, the sound does not match with video

    Hi,
    I would like to ask a question. I have AE CS6, and I recorded a gameplay video with Avermedia Live Gamer HD. The format of this video is .mp4. When I import the .mp4 into the program, the sound does not match. On the original video, when i play with VLC or WMP, all things are good, and when i import, the sound does not good. What causes this problem, and can I do something to solve this?
    Thanks the answers, R3dLinE

    Check your footage interpretation, split the audio in an external program, convert the sample rate and import it separately or whatever. Most likely you simply have used unsuitable recording settings with odd sample and data rates.
    Mylenium

  • Difference between the different structures while dealing with User-Exits

    While dealing with User-Exits, we come across the different structures/Tables like XVBAP,YVBAP,TVBAP,IVBAP,*VBAP....
    What is the difference between them ?

    Usually X<tablename> and Y<tablename> are used in change document management to determine records updated (Y is old values and X new ones).  (Look at transaction SCDO)
    T<tablename is an internal table read from database and I<tablename> is an import table parameter of the same structure. <tablename> is an equivalent of <tablename> declared with statement TABLES and contains usually the "old" value.
    Look at exit documentation. start at [User Exits In Sales Document Processing|http://help.sap.com/saphelp_46c/helpdata/en/1c/f62c7dd435d1118b3f0060b03ca329/content.htm]
    Regards

  • How to restrict user rights so they can add list items but cannot edit them once saved?

    I appreciate if you can help me with this. My beloved company uses SP2010, and I got the task to solve this issue using it, though I am not a programmer (basic html is still ok).
    I need a simple annual leave list with the following capabilities:
    1. Group of users (~100 members) should be able to create list items in a list that contains annual leave data. Columns are: Name, Leave start date, Leave end date, Team leader, etc.
    2. Once they fill in the new item form, a workflow notifies the team leader to visit the item and set a column "approval status" to approved or rejected.
    3. Based on this column value, another workflow notifies the requestor about the decision.
    4. After approval, users should be able to see their items in the list, but they should not be able to edit it.
    Sounds so simple, but I have big issues with point 4. as Sharepoint does not differentiate create and edit rights to a list item. As a result, requestor can edit dates of the approved items.
    Any hints how to solve this? Can impersonation help with this? Or should I add a new permission level to the site?

    Hello
    We are going to do the following things to accomplish your task
    create a new security permission level that will allow submit only
    create your annual leave list
    assign everyone the submit only permission
    add a workflow to send the email and modify the item permissions
    Ok first things first, on the sharepoint server open a powershell window and type the following powershell:
    $spweb=Get-SPWeb -Identity "<site url>";
    $spRoleDefinition = New-Object Microsoft.SharePoint.SPRoleDefinition;
    $spRoleDefinition.Name = "Submit only";
    $spRoleDefinition.Description = "Can submit/add forms/files/items into library or list but cannot view/edit them.";
    $spRoleDefinition.BasePermissions = "AddListItems, ViewPages, ViewFormPages, Open";
    $spweb.RoleDefinitions.Add($spRoleDefinition);
    $spweb.Dispose();
    Now in your site you will have a new permission level called 'Submit Only'.
    Create your annual leave list and give all users read and submit only permissions.
    Now create a workflow against this list in sharepoint designer.
    Add a new step which should be an impersonization step
    1st action
    add permission: give the user and their manager (i am presuming you are capturing this information in your list so it will be recorded against the item) whatever control you wish, i.e. full control, contribute, etc.
    2nd action
    remove list permission: remove the group you initially gave read and submit only permission to and select the read and submit only permissions to remove from them, i.e. if you added the 'All Users' group, then when performing this action choose to remove
    the read and submit only permissions for the users 'All Users'.
    3rd Action
    Send an Email: Email Manager with notification.
    Regards
    Sergio Giusti
    http://sergioblogs.blog.co.uk/
    Whenever you see a reply and if you think is helpful, click " Vote As Helpful". And whenever you see
    a reply being an answer to the question of the thread, click "
    Mark As Answer".
    i just face the same issue and i create a new Permission level named "Submit Only". but i also have a custom web part that is added to my Create form . so when users tried to access the Create form they will get Access Defined. so is there a way to
    modify the permission level to be able to read web parts ?

  • Recent software upgrade has changed the way my iPhone syncs with my macbook, and diary items no longer upload from my iPhone. I've tried a to fix it and seem to have made things worse. What is the best way to get the two devices in sync ?

    Recent software upgrades has changed the way my iPhone syncs with my macbook and items entered on my iPhone are no longer uploaded to my macbook. I've tried to fix it and seem to have made things worse, my iPhone now has a long list of calanders that I don't want and can't delete and nothing is uploading to my macbook.

    You need to look at Mac's iTunes, check  > System Preferences > iCloud.
    If you use iCloud for Calendar, Contacts then turn off those items in iTunes, Info tab with your iPhone connected and selected.

  • Best way to link user form with user table

    Hi all.
    What is the best way to link an user form with a user table (with all of the functions, add, update...)? I have created a simple form, and the question is next:
    depending the type object of the user table (document, master...) i have facilities to imlement the basic operations in the form?  if i create an UDO i have the functions but i want to use the form that i created with a screen painter.
    Thanks.

    Hi again i want add a new comment please.
    If i want do all functions (add,update...) of my form in my user table, and i want my user table is a <b>type document</b>? how can add new lines in my user table with objet <b>type document</b>? because when i make the instance i nedd to say what type of document is (item,order...) and when i do an add(), not add() in my user table. In what moment or how can assign that the add,update functions... affect in my table?
    Thanks again.

  • HT4796 It is impossible to pass the log in phase using an user created by the migrate PC to MAC Assistant

    The migration assistant (PC Windows Vista Premium edition to MAC) has created a new user on the MAC. Unfortunately it is impossible to log the system in using that user: no password accepted. I tried to change the user password but the login result still impossible.
    Thanks in advance for any suggestions.

    Hi user,
    Welcome to OTN world.Always share your Jdev version.
    Why are you not storing the login user name into a session variable and store it into your table.

  • Unable to log onto domain controller with user account

    Hi,
    I am able to log onto my DC as domain admin. I cannot log on as myself. I do not see what I am missing in the GPO to make this happen? I am part of a server admin group and would like the server admin group to be able to log on to the domain controller to
    maintain the server. 
    Any suggestions?
    Wave~Chaser

    Log on to this DC and run rsop.msc and check the following policies:
    Computer Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment\Allow log on locally
    Computer Configuration\Windows Settings\Security Settings\Local Policies\User Rights Assignment\Deny log on locally
    Add your self to Allow log on locally
    (in default domain controller policy - as I mentioned above) and make sure your user account not belong to any group that have Deny log on locally.
    Please take a moment to Vote as Helpful and/or Mark as Answer where applicable. Thanks.

Maybe you are looking for

  • *** HDV print to video stutters and never gets going.

    I'm working in HDV and trying to print my project to video and am having absolutely no success. I've checked and my camera IS connected. I conformed to HDV before choosing file>print to video and then DID to the latter. When I press record on my came

  • Seeburger in Integration repository

    Paging Seeburger Xi gurus, 1)  We have installed the Seeburger BIC and AS2 adapter,  I was going through the Seeburger documentationSAPXI_ContentGuide_CONSUMER_en.pdf . On page 13, it seems we should be seeing the Message Mappings(Idoc to XML EDI or

  • Changing layout mgr... can this be done?

    I have created an application with an all NULL layout. I used NULL because the application doesnt need to be resized. My problem is that i created the program for a specific computer that i was told used an 800x600 screen resolution when in fact it u

  • Microsoft for Mac documents are not compatible with PC versions

    THIS IS DRIVING ME UP THE WALL PLEASE HELP!!! I love Apple computers, but I may not be able to get one for my next laptop because of compatibility problems with Microsoft for Mac. Whenever I work on something for school on my Mac using word or PowerP

  • In clause with default_where

    hi all, i am using forms6i. i have to query a data block with in clause query Go_Block('EMPLOYEE_MASTER'); Set_Block_Property('EMPLOYEE_MASTER',Default_Where,'emp_dept IN ('''||:dept||''''||')'); Execute_Query;in my code 'dept ' is the field where i