Problem related to User Management through Programming Vs Sharepoint Administration
There is a subsite X (http://P/Sites/x) under the portal P(http://P/). The Portal P Home page(http://P/Default.aspx) has a webpart that displayes the links to various subsites that the user has access to. The code this webpart uses to display the links is shown below under headingCode-A.
The subsite X has a feature of adding users to the subsite which is implemented programmatically (Please seeCode-B). If I add a user using this feature, I can see the user among the siteusers using SiteSettings>>ManageUsers list for subsite X. However the link to X does not appear in the homepage of P. But if I add a user to the subsite X using the administrative link Sitesettings>>ManageUsers>>AddUser then the link to the subsite X appears in the Portal Homepage.
So please help me in getting the difference between these two ways of adding a user to a site so that I can show the link to the Subsite X in portal home page when a user is added to the subsite X programmatically.
Code-A
SPGlobalAdmin globAdmin = new SPGlobalAdmin();
foreach(SPVirtualServer vServer in globAdmin.VirtualServers)
{
SPSiteCollection sites = vServer.Sites;
for(int intI=1; intI<sites.Count; intI++)
{
SPWeb subSite = sites[intI].AllWebs[0];
//if the subsite is under sites
if (subSite.Url.IndexOf("sites")>0)
{
try
{
subSite.Users.GetByEmail(strEmail);
TableRow tblRow=new TableRow();
TableCell tblCell=new TableCell();
tblCell.CssClass= "ms-vb";
HyperLink hlnkSite=new HyperLink();
hlnkSite.Text=subSite.Title ;
hlnkSite.NavigateUrl=subSite.Url;
tblRow.Cells.Add(tblCell);
objTbl.Rows.Add(tblRow);
}
catch(Exception ex)
{
//if user is not found the 1st statement under try will cause error.
//hence ignore without doing anything.
//for a user who is added using AddUser feature of subsite x, the above GetByEmail is failing with error User Cannot be found.
}
}
}
}
Code-B
Dim imp As WindowsImpersonationContext = createIdentity(strUser, strUserDomain, strUserPassword).Impersonate()
Dim objSPRoleAdmin As SPRole = objWeb.Roles("Administrator")
objSPRoleAdmin.AddUser(userLogin, userEmail, useName, userNote)
imp.Undo()
--
Thanks in advance from
Satish

