When you are using Claims based authentication method, the user is never added SharePoint SiteCollection unless the user has logged to the site for the 1st time. However, when a user logs into the site for the first time, its identifier is only stored in a UserList List.
If you have a need to send emails to user as per of workflow or alert or anything, you need to find a place to store them. You could easily use the UserList to store this information. As a user is entering your site, you could write code to query the claims to extract email address the user primarily has and then extract that value and store it to the User List.
The location of this list http://myserver/_catalogs/user/Simple.aspx
Specail Consideration with this list:
- User List is very notorious as to when it updates the data.
- Initially when you create a new Site Collection, this list shows less than 15 columns and then a timer job runs and it adds around 40 more columns to the list.
- This list can only be seen by Site Collection Admin and above.
- In order to update to this list, you should ue run with elevated privs.
I will post some sample code soon.
Wednesday, July 27, 2011
Monday, July 25, 2011
Auto Increment Columns in SharePoint 2010/MOSS
As more and more applications are using SharePoint to store data and they want it to work simillar to SQL. How do you create auto increment columns?
The process is pretty cool. It would require sing SPD workflow.
Here are the steps:
-Add another column to list (Note: You cannot use ID as that is the internal column)
-List Settings->Advanced Settings->Manage Content.
-From List Settings page, click Item Content Type, and then click new column name.
-Next, choose the option to hide the column in the form.
-Goto SPD and create a workflow with "Update Item" in the list action and then set the new column to a value with current item:ID .
-Check for errors->Publish - >Save
-Finally, don't forgot to check the workflow to be staretd automatically as this is not the default.
The process is pretty cool. It would require sing SPD workflow.
Here are the steps:
-Add another column to list (Note: You cannot use ID as that is the internal column)
-List Settings->Advanced Settings->Manage Content.
-From List Settings page, click Item Content Type, and then click new column name.
-Next, choose the option to hide the column in the form.
-Goto SPD and create a workflow with "Update Item" in the list action and then set the new column to a value with current item:ID .
-Check for errors->Publish - >Save
-Finally, don't forgot to check the workflow to be staretd automatically as this is not the default.
Demystify Title Column in SharePoint 2010 List/MOSS
When you create a new SP List, you see a default Title column. If you try to delete this column, you don't see the option to delete when you goto List Settings->Columns. Have you wondered why you cannot delete this column?
The answer is because when you create a custom list, it is created with "Item" content type. This "Item" content type has 1 field and it is required field.
How do you delete the Title column?
Goto List Settings->Advanced Setting -> Choose Manage Content Types.
Then, from List Settings-> Click Item Content Type and there you will get the optional to make changes to Title column!
The answer is because when you create a custom list, it is created with "Item" content type. This "Item" content type has 1 field and it is required field.
How do you delete the Title column?
Goto List Settings->Advanced Setting -> Choose Manage Content Types.
Then, from List Settings-> Click Item Content Type and there you will get the optional to make changes to Title column!
Monday, July 18, 2011
Different Kinds of Pages in SharePoint 2010
Did you know there are 3 kinds of pages in SharePoint 2010
- WikiPages -> A new kind of page available in SharePoint 2010. Used primarily like a free for all wiki page for adding Tables etc. This may contain WebParts
- WebPart Pages -> Existed in SP2007 and SP2010 -> A more structured page with layouts/zones/webparts etc.
- Publishing Pages ->Specifically for publishing
In addition, there are Application pages that are physically stored on the server.
- WikiPages -> A new kind of page available in SharePoint 2010. Used primarily like a free for all wiki page for adding Tables etc. This may contain WebParts
- WebPart Pages -> Existed in SP2007 and SP2010 -> A more structured page with layouts/zones/webparts etc.
- Publishing Pages ->Specifically for publishing
In addition, there are Application pages that are physically stored on the server.
Thursday, July 14, 2011
How to get total number of users logged in a day?
There is no direct way of retrieving this information. You have to solution out to get this data. In this article, I have outlined what needs to be done in order to get this data.
Step 1:
- Create a basic delegate control and add it to your MasterPage. In the delegate control, all you do is write code like this to update the OOB SharePoint list that manages all users who have logged into the site. This list can be accessed from this URL
http:/Your Server/_catalogs/users/simple.aspx
========================================Code=========================================================
//You have to run this with elevated privilidges as the user would not have access
//to this list. The list can only be accessed by Admin.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
try
{
using (SPSite oSiteCollection = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb oWeb = oSiteCollection.RootWeb)
{
oWeb.AllowUnsafeUpdates = true;
SPList myUserList = oWeb.SiteUserInfoList;
SPListItem myUserItem = myUserList.Items.GetItemById(myLoggedInUser.ID);
myUserItem["Name"] = myUser.FirstName + " " + myUser.LastName;
myUserItem["Work e-mail"] = myUser.EmailAddress;
myUserItem.Update();
}
}
}
catch (Exception e1)
{
SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("External", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "SecurityWebPart.AddPersonalDetailsToSite-" + e1.Message, "");
}
});
========================================Code=========================================================
This code really does not do much, you can even just put the update statement. When you add this code, it will put the time stamp when the user last logged onto your site.
Step 2
Then, write a timer job to extract daily logged user information from the above list and store it in another List. The reason you have to do this is so as to maintain the history.
Step 3
Finally, you can present your information in a webpart or directly from this list.
Step 1:
- Create a basic delegate control and add it to your MasterPage. In the delegate control, all you do is write code like this to update the OOB SharePoint list that manages all users who have logged into the site. This list can be accessed from this URL
http:/Your Server/_catalogs/users/simple.aspx
========================================Code=========================================================
//You have to run this with elevated privilidges as the user would not have access
//to this list. The list can only be accessed by Admin.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
try
{
using (SPSite oSiteCollection = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb oWeb = oSiteCollection.RootWeb)
{
oWeb.AllowUnsafeUpdates = true;
SPList myUserList = oWeb.SiteUserInfoList;
SPListItem myUserItem = myUserList.Items.GetItemById(myLoggedInUser.ID);
myUserItem["Name"] = myUser.FirstName + " " + myUser.LastName;
myUserItem["Work e-mail"] = myUser.EmailAddress;
myUserItem.Update();
}
}
}
catch (Exception e1)
{
SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("External", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "SecurityWebPart.AddPersonalDetailsToSite-" + e1.Message, "");
}
});
========================================Code=========================================================
This code really does not do much, you can even just put the update statement. When you add this code, it will put the time stamp when the user last logged onto your site.
Step 2
Then, write a timer job to extract daily logged user information from the above list and store it in another List. The reason you have to do this is so as to maintain the history.
Step 3
Finally, you can present your information in a webpart or directly from this list.
Wednesday, July 13, 2011
Troubleshooting: The user does not exist error or is not unique
Today I was rebuilding my VM as a result of some issue with the old VM. An authenticated claims user when added to a SPGroup threw the following error:
The user does not exist or is not unique.0x81020054 "} System.Exception {System.Runtime.InteropServices.COMException}
I banged my head for some time before found out the problem was in the setup of WebApp. In my case, the WebApp had 2 STS Providers so it was pointing to the wrong STS Provider, which was causing the user to be not added to the group. However, the user was an authenticated user who could be directly assigned access to a resource, but not added to the group. The user was added and viewable from this URL-> http://YOURSERVER/_catalogs/users/simple.aspx.
The above solution is only applicable if you are using Claims Based Authentication.
The user does not exist or is not unique.
I banged my head for some time before found out the problem was in the setup of WebApp. In my case, the WebApp had 2 STS Providers so it was pointing to the wrong STS Provider, which was causing the user to be not added to the group. However, the user was an authenticated user who could be directly assigned access to a resource, but not added to the group. The user was added and viewable from this URL-> http://YOURSERVER/_catalogs/users/simple.aspx.
The above solution is only applicable if you are using Claims Based Authentication.
SharePoint 2010 Administration Toolkit - Really cool
This is a great tool kit especially for administrators... Love the reports that are generated..This not only gives the reports, but also includes the following:
•Security Configuration Wizard (SCW) manifests
•Load Testing Toolkit (LTK)
•User Profile Replication Service
•Content Management Interoperability Services (CMIS)
Here is the link to install the kit
•Security Configuration Wizard (SCW) manifests
•Load Testing Toolkit (LTK)
•User Profile Replication Service
•Content Management Interoperability Services (CMIS)
Here is the link to install the kit
Subscribe to:
Posts (Atom)