Wednesday, June 15, 2011

Everything you need to know about Document Ids in SharePoint 2010

Document Id is a cool feature in SharePoint 2010. It has many uses that you you would not consider it using initally. However, with time you will find that it is a simple out of the box feature that has power. When you turn this feature on, SP will add a new column "Document Id" to all document libraries. SP will also display a new link [Document ID Settings] in Site Collection Admin section, which will be used to configure this feature. SP randomly generates a set of characters that it will use to prefix every document ID. You can change the document ID's initial characters.

Document Ids are not preseved when moving the document library from 1 enviornment to another.

If you don't like the algorithm associated with generating document id, you can extend the functionality using Visual Studio.

If you closely look at the URL associated with the Document Id, it is actually referring to an asp page and passing the ID as QS paramter. The page[DocIdRedir] is basically a router that is accepting an ID and redirecting to the location of the document.
http://sp2010dev01/_layouts/DocIdRedir.aspx?ID=RTTT-1-4


When you copy this document to another location, SP creates a new document id.

How do you turn on this feature?
You can turn on this feature by activating a Document Id Service via Site collection feature page. You could also do it via PowerShell.

What happens when you trun on this feature?
Document ID assignment job gets scheduled to be run 8 hrs from the moment the service has been turned on.

How to create a Digicert.cer

Instructions
1. Open the YOUR.cer certificate.


2. Click on the Certification Path tab and highlight DigiCert. Click on View Certificate.

3. In the Details tab, click on Copy to File.


4. The Certificate Export Wizard appears. Click Next.


5. Select the default ‘DER encoded binary X.509 (.CER)’ option. Click Next.


6. Specify a file name and a location to export the certificate to. Click Next.


7. Click Finish to complete the Export Wizard. The digicert.cer certificate is created in the specified directory.

8. Run the following commands using SharePoint 2010 Management Shell to add the trusted root authority.
$root = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("c:\temp\digicert.cer")
New-SPTrustedRootAuthority -Name "YOUR Token Signing Root Authority" -Certificate $root

ADDING A TRUSTED ROOT AUTHORITY

The following command creates a new trusted root authority .

$root = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("c:\temp\YOUR.cer")
New-SPTrustedRootAuthority -Name "Token Signing Root Authority" -Certificate $root

If you receive an error that states that ‘The root of the certificate chain is not a trusted root authority’, like in the image...then you will need to get the root of the certificate and add it to SharePoint’s list of trusted root certificates

How to check which users have logged in SharePoint?

If you need to ever find out, which authenticated users have logged into your site, you need to visit this page. You have to be the Site Collection admin to see this list.

http://SERVER/_catalogs/users/simple.aspx

This will provide you the information about the user when was the 1st time the user ever logged into the site. This list is a hidden list. This list by default has 33 columns describing the user and the extended version of this list has 64 columns.

If you ever have a need to check when a user has logged in last time, you could simply add a small web part to the home page of your site. The main function of the web part is to update the list. When you update a row of data, it automatically puts the time stamp of the last modified date.

Here is some sample code:

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.Update();
}
}
}
catch (Exception e1)
{
Your Error Handling
}
});

Tuesday, June 14, 2011

Application Pages

Application Page rendering?

- Open VS 2010 and a feature project.
- Add an Application page. (VS will create layouts/project name (folder)/Name of the application page.
- Now deploy the feature.

Note: You can verify that the application page has been deployed by going to 14 Hive/Templates/Layouts/Project Name folder.

You can access the application page from this URL http://SERVER/_Layouts/Project/Application Page.aspx

However, if you access this page relative to a document library/list (Example: http://SERVER/DocumentLibrary/_Layouts/Project/Application Page.aspx, it does not give you 404, but gives you Rendering error!!!

Monday, June 13, 2011

How to prevent users from renaming folders?

Scenario: Need to prevent users from modifying the folder name in a document library
Solution: You need to add an item updating event to the library.

Here is some sample code:

try
{

if (properties.ListTitle == "YOUR LIBR")
{
//Only perform this check if the user is not a site collection admin.
if (!properties.Web.CurrentUser.IsSiteAdmin)
{
if (properties.ListItem.FileSystemObjectType == SPFileSystemObjectType.Folder)
{
properties.Cancel = true;
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
properties.RedirectUrl = properties.WebUrl.ToString() + "/_Layouts/...../ErrorPage.aspx?errormessage=" + "Cannot rename the folder";
}
}
}

}
catch (Exception e1)
{
properties.Cancel = true;
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
properties.RedirectUrl = properties.WebUrl.ToString() + "/_Layouts/..../ErrorPage.aspx?errormessage=" + e1.Message;
}
finally
{
if (!properties.Cancel)
{
base.ItemUpdating(properties);
}
}

}

A few notes:
- If you don't specify the redirect URL, SP will show a nasty dialog box like ASP.NET crashed or something with your message.This may not be liked by the business.

- You should always check for the type of object you want to prevent from getting updated.

- If there is a typo or you missed "/" in your RedirectURL, SP will display the nasty box and ignore going to ur Application page.

Thursday, June 2, 2011

List item limit 5000 details

I don't like the way Sharepoint has implemented the logic for 5k item. Consider a scenario where there are 7k items in the list in form of documents and folders. A non admin user clicks the list, Sharepoint at that time goes to SQL and fetches 1st 5k rows of data. In the UI you will by default see 30 items per page due to pagination. The user starts going next next and when it reaches 5k limit, it does not complain ithe browser keeps spinning!!!

I don't understand why it does not tell the user the reason it cannot process. More important, I don't like fact that since it is paginating why it needs to pull all 5k first time the user accesses the list.

Search not working

Followed all the instructions to enable search including, but not limited to following

- created a content source
- ensured the account used for crawling had access
- verified no cert warnings

Checked crawl logs. Everything looked clean but still when searched nothing returned

The problem alternate access mapping & reverse proxy!!!

Core.js blocked

Have you ever seen that core.js getting blocked ? Recently in my project we noticed that users were not able to see the drop down menu on any list items when they were accessing it from outside the network. Some of the functions of ribbon were also getting disabled. The problem was due to reverse proxy setup that was causing this error. Once we fixed the proxy issue it started working fine.