locked
adding user to user profile? RRS feed

  • Question

  • I can not understand below code. Why it is adding and removing again. But I can get user information in user profile.  How it is possible?

                    SPWeb web = null
    
    ;
     SPSecurity.RunWithElevatedPrivileges(delegate () {
     string sWebName = ConfigurationManager.AppSettings["MossSiteName" ];
     web = new SPSite(sWebName).OpenWeb();
    });
     web.AllowUnsafeUpdates = true ;
     //MossRegUserGroupName = Communities Visitors <br/> string sGroupName = ConfigurationManager.AppSettings["MossRegUserGroupName" ];
     SPGroup group = web.Groups[sGroupName];
    //MossSqlMembershipProvider = AspNetSqlMembershipProvider <br/> string sProviderName = ConfigurationManager.AppSettings["MossSqlMembershipProvider" ]; group.AddUser(sProviderName + ":" + constitId, email, firstName + ' ' + lastName, status + ' ' + constitId); group.Update(); SPUser user = web.AllUsers[sProviderName + ":" + constitId]; group.RemoveUser(user); group.Update(); Console.WriteLine("Added SharePointVisitor" + constitId);










    Jamsbond
    • Edited by Mike Walsh FIN Tuesday, September 15, 2009 7:26 AM do NOT use more than one question mark´in Titles. two removed
    Tuesday, September 8, 2009 7:36 PM

Answers

  • This piece of code would basically import the fba user information into the Users collection of the SPWeb.  This would probably only be useful for WSS 3.0 since MOSS has a profile importer.  WSS only adds user information to its db's when a user is added to a site.  I'm not sure what database it is being populated into, but thats essentially what this piece of code is doing. 
    Chad Clarke
    • Marked as answer by ItsMeSri Wednesday, September 9, 2009 2:40 PM
    Tuesday, September 8, 2009 9:35 PM

All replies


  • Did you write the code?  It looks like demo code to show the use of RunWithElevatedPrivileges and forms based authentication.

    > Why it is adding and removing again
    It's a demo?

    (BTW, it's a demo of add / removing a user to a group, not adding a user to FBA)

    Am I misunderstanding your question?
    Mike Smith TechTrainingNotes.blogspot.com
    Tuesday, September 8, 2009 8:06 PM
  • It is not demo. Someone wrote this in my company, Now I am understanding. This code is adding use to FBA tables. 1st it is doing Membership.CreateUser and then after that above code is executing. 

    My question is if they are adding to user to group and remove again. I am able to get user information in people picker like fname and lname and email. How it is possible?

    Where is this information available in sharepoint database.

    Jamsbond
    Tuesday, September 8, 2009 8:57 PM
  • > are adding to user to group and remove again

    yes, and that has an interesting side effect... the user remains in the "All People" list of the site collection.

    I'm guessing the code might be a way to "preload" a user's profile to a site collection.  
    Mike Smith TechTrainingNotes.blogspot.com
    Tuesday, September 8, 2009 9:31 PM
  • This piece of code would basically import the fba user information into the Users collection of the SPWeb.  This would probably only be useful for WSS 3.0 since MOSS has a profile importer.  WSS only adds user information to its db's when a user is added to a site.  I'm not sure what database it is being populated into, but thats essentially what this piece of code is doing. 
    Chad Clarke
    • Marked as answer by ItsMeSri Wednesday, September 9, 2009 2:40 PM
    Tuesday, September 8, 2009 9:35 PM