Friday, June 29, 2012

BLOB Cache


This is a feature for Microsoft SQL Server and this is designed to move the storage of binary large objects (BLOB) from database server to a disk storage location. It reduces the database load and increases the browser performance. It is very useful for frequently used images, audio, video and other media type files. The BLOB cache is enabled in front-end server and improves the performance by retrieving the BLOB files from database to a directory. This reduces the network traffic between SharePoint and database server.

Before use BLOB cache we have to well plan weather this will improve performance or not. If most of the files in a site are static, the files are not getting updated frequently and it contain many read-only media files, enabling BLOB cache will improve the performance.

You must specify a storage location to store the files in the front-end web server. The storage location should have enough disk space to store the cache. And also select a drive that will be used by few processes as possible.

The BLOB caching is done at the Web application level. All the site collections under the web applications will be effected. By default the BLOB cache is off.

To configure BLOB cache 
1.       Open IIS in the SharePoint server and click on the specific web application 
2.       Right click on the name of the web application and click Explorer.
3.       Open the web.config file. Before make changes to the web.config file. It is good to keep a copy of that.
4.       Find the tag and change the attributes 
5.       Change the location attribute to specify the directory to cache the files.
       Ex: location="C:\BLOB"
       Microsoft recommends specifying a directory that is not the same drive as the Operating System runs.  
6.       For the path attribute modify the regular expression to add/remove file extension. These types of files will be cached at the specified location. 
7.       maxSize is the maximum allowable size of the disk based cache in GBs. 10 GB is the default size. 
8.       enabled attribute enable/disable the cache. Set it to true. 
9.    max-age specify the maximum amount of time in seconds that the client browser caches BLOB. The default value is 86400 seconds (24 hours). 
10.   Save the web.config file.

Your BlobCache tag looks like this

<BlobCache location="C:\BLOB"
path="\.(gif|jpg|jpeg|jpe|jfif|bmp|dib|tif|tiff|ico|png|wdp|hdp|css|js|asf|avi|flv|m4v|mov|mp3|mp4|mpeg|mpg|rm|rmvb|wma|wmv)$"
              maxSize="10"
              enabled="true" />

When you change the web.config file, the web application in IIS automatically recycles. The recycling can cause some interruption in the services to sites contained in that web application.

After the recycling process, if you go the directory you specified in the location attribute (C:\BLOB), you will see some set of files like Change.bin, dump.bin, flushcount.bin, etc.. This files contain information about the cached files.

To do the test on BLOB cache 
1.      Upload a .wmv file to the Shared Documents library. 
2.      Try to download the file to the client computer. 
3.      Go to the location directory (C:\BLOB). You can see the file is stored in this location. In my case my site collection name is ‘Test 1’ and I upload the documents to Shared Documents. The .wmv file stored in ..\ SITES\TEST1\SHARED DOCUMENTS

Every time when a new file rendered from database, it will be stored in the disk drive. The .bin files will get updated with index and other metadata information.

Once you upload a file to a library you will not find the file in the disk drive immediately. It will be stored to the disk only when you start download. And the file will be there for the time period specified in the max-age attribute.

Thursday, June 28, 2012

Customizing My Profile Tabs in SharePoint 2010

In SharePoint 2010 My Profile page you can find tabs like Overview, Organization, etc.. SharePoint provide the flexibility to add, edit and delete tabs, add navigation link and change the order of the tabs.




The default tabs are shown in the above picture. The tab urls are as follows.

Tab                   Tab Url
Overview             /person.aspx
Organization        /OrganizationView.aspx
Content                /personcontent.aspx
Tags and Notes    /_layouts/thoughts.aspx
Colleagues           /_layouts/MyContactLinks.aspx
Memberships       /_layouts/MyMemberships.aspx 
 
Follow the steps to do the modifications on the tabs. You should log in as an administrator to do the changes. 
1.       Go to My Profile page. 
2.       From Site Actions menu, select Site Settings. 
3.       Under Look and Feel, select Quick Launch link. 
4.       There you can find the settings to add new navigation links and modify existing tabs.

For example: To add a tab call Libraries, which will direct to libraries page. 
1.       Click New Heading
2.       Type the address as ‘/_layouts/viewlsts.aspx?basetype=1’ 
3.       Type the description as ‘Libraries’ 
4.       Click Ok

The Libraries tab will display in the My Profile page.

Friday, June 22, 2012

Avoiding memory leaks in SharePoint custom development


When you doing custom development in SharePoint like webparts, event receiver, etc.. it is important to consider memory leaks. Creating the component in safe way lead to improve the performance.  There are some points we can consider to avoid memory leaks.

1.       Use Dispose() method. 
2.       Use SPDisposeCheck utility to identify issues.

Dispose() is not related to SharePoint, it is provided in .NET. As a .NET developer we have to know how to correctly release the resources while working with the objects. .NET framework has a concept of garbage collection, provided by Common Language Runtime. Whenever you create an instance of managed type, when it is no longer used, the Garbage Collector will automatically release the allocated memory. But this is non deterministics (unpredictable).

.NET framework provide IDisposable interface which expose a Dispose() method that you can call explicitly to release the unmanaged resources.

To use Dispose technique you can follow one of the following methods. 

1. Use the using keyword
    Ex:
   using (SPSite site = new SPSite(“http://address”))
        {
           //your code
        }

 2. Use try/finally code block
    Ex:
  SPSite site = null;
  try               
     {
         site = new SPSite(“http://address”);
         //your code
     }
  finally
     {
       if (site != null)
          site.Dispose();
      }

 3. Explicitly call Dispose() method.
      Ex:
    SPSite site = new SPSite(“http://address”);
       //your code
    site.Dispose();


SPDisposeCheck is a tool that helps the developers and administrators to check custom SharePoint solutions that use the SharePoint Object Model. It measures against dispose best practices. Following is the way how to use SPDisposeCheck utility. 

SPDisposeCheck is a command line tool normally installed to this location “C:\Program Files (x86)\Microsoft\SharePoint Dispose Check”.

Go to any dll that you have developed using Visual Studio. My dll path is: “C:\Users\t-ictdev05\Documents\Visual Studio 2010\Projects\TestSPProjects\BlogPost\BlogPost\bin\Debug”.

Now open the command prompt and enter the following command:
“C:\Program Files (x86)\Microsoft\SharePoint Dispose Check\ SPDisposeCheck.exe” “C:\Users\t-ictdev05\Documents\Visual Studio 2010\Projects\TestSPProjects\BlogPost\BlogPost\bin\Debug”


It will show the problems in the specified dll.

If you want you can write this result to a txt file by using following command.

“C:\Program Files (x86)\Microsoft\SharePoint Dispose Check\ SPDisposeCheck.exe” “C:\Users\t-ictdev05\Documents\Visual Studio 2010\Projects\TestSPProjects\BlogPost\BlogPost\bin\Debug” >result.txt

By using this utility you can identify what are the object we can dispose to develop a safe code.