MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

Programmatically populating "People And Groups" field with users

  Asked By: Ciera    Date: Dec 23    Category: MOSS    Views: 7155

I am currently working on a SharePoint state machine workflow in Visual Studio
2008 for MOSS 2007. I am currently experiencing some issues however.

The problem I am having is populating a standard SharePoint "People and Groups"
field with a user who is not yet part of a site. The code examples I have seen
utilize something similar to the following:

foreach (SPUser user in site.RootWeb.AllUsers)

if (user.LoginName == AccountId)
listItem["User"] = user.ID;

There are two issues that I see here relating to my issue. Since we use an SSP
thats populated from AD, its practically impossible to have everyone as part of
the site which means searching through site.RootWeb.AllUsers will obviously not
turn up everyone we are searching for.

The other issue is how we are populating the field - user.ID
If there were a different way to populate a user field, maybe with login ID,
problem would be solved... but I am not finding much information on this. Maybe
I am searching using the incorrect terminology.

As some background information, to find which user should be populated in the
field, I am using an InfoPath contact selector control which provides me the
Display Name, AccountID, and AccountType. So I have at least that information
available to me.

Any insight that can be provided would be excellent. I hope I am simply
overlooking something obvious.



2 Answers Found

Answer #1    Answered By: Marc Dixon     Answered On: Dec 23

HTTPContext.Current.User will get the logged in user's login id.

Answer #2    Answered By: Johathan Mcgowan     Answered On: Dec 23

Not sure I understand the problem clearly.

If an user is not an user of an site/web, you could use spweb.ensureuser to add
the user to the web if not there already.