Tuesday, July 7, 2009

MySIte Customization

In Sharepoint, a user can have his own personal site where he can add his personal information, documents and other related information. Sharepoint dont have any built-in mechanism to customize the look and feel of MySite template. If we wants to customiza it through Sharepoint designer then we will have to customize it for each user seperately. What if we wants to have a custom template for MySite common to all users? We will have to change its master page. The master page for MySite can be found at
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL\ application directory with name default.master.
we can open it in Sharepoint designer and customize it to give look and feel. But this is not a recommended approach. If we will modify the default.master, then we will not be able to use default view of mysite anymore as we are customizing the master page from site definition.
An alternate and recommended way to do it is feature stapling. In feature stapling, we can create a custom master page and replace that with default.master at run time using the feature.

The site templates for MySite are-


  • SPSPERS (private view)

  • SPSMSITEHOST (public view)



The master page for these two templates need to be replaced with our custom master page. I found a great blog by sridhar to achieve the feature stapling-

http://blogs.msdn.com/sridhara/archive/2007/05/19/customizing-mysite-in-moss-2007.aspx

Using this blog I was able to customize the look and feel of master page.
Now my next task was to add a content editor webpart in default.aspx. The solution for this is a bit tricky. I had to play with ONET.XML to add the webparts.

Here is the steps I followed

1. Open the ONET.XML file from the location - C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\SiteTemplates\SPSPERS\XML\ using some editor.( dont forget to take a backup of the same.)
2. Find the Modules tag and then tag 'AllUsersWebPart' .
3. Remove all the lines inside tag 'AllUsersWebPart' and add the following lines-
http://schemas.microsoft.com/WebPart/v2< /a>"> Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c Microsoft.SharePoint.WebPartPages.ContentEditorWebPart Use for formatted text, tables, and images. 1 None true true true /_layouts/images/mscontl.gif true < xmlns="< a href=">http://schemas.microsoft.com/WebPart/v2/ContentEditor< /a>" /> < xmlns="< a href=">http://schemas.microsoft.com/WebPart/v2/ContentEditor"><div><TABLE< /a> style="WIDTH: 100%" summary=""><TBODY><TR><TD>&nbsp;Put your title here</TD></TR><TR><TD>&nbsp;your picture here</TD></TR><TR><TD>enter your detail</TD></TR></TBODY></TABLE></div>< /content> < xmlns="< a href=">http://schemas.microsoft.com/WebPart/v2/ContentEditor< /a>" />
]]>

If you dont want to see the other webpart, you can comment or remove them.
4. save and close the ONET.XML
5. Do an IIS reset.

Thats it. Now the default.aspx will display content editor webpart.

Adding custom links
To add custom left links and remove the links coming on the left, do the following-

Open ONET.XML and find 'navbar' tags. 'navbar' tag is for links coming on left. this tag has 'name' attribute, the value of this attribute (prefixed by dollor) is coming from resource file core.resx. we can find this file at location- C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\Resources\.
So when we add our custom link, we will have to add them in resource file also. tag also have attributes ID and URL. give an unique ID value in ID attribute and give URL of the page to the attribute URL. suppose I am adding a link Home. then entry would be-

For this, the entry in the resource file would be-
Name -- category_MySiteHome
value-- Home

Its fine. Now comment the existing tag and add your custom link by adding new entry. dont forget to put an entry in core.resx file for each tag you have added. Now save and close the ONET.XML. do an IIS Reset. your custom link will be visible on the default.aspx page of MySIte.

'Home' will be the text appeared on the link.

Adding built-in page for custom links

Now we have created custom link. we would like to have a custom page which will be linked to the custom link we have created.
Create an ASP.Net Application. Add a page home.aspx into the application. In the aspx file, put proper HTML and webpart zone as you want to be on the page. If you are adding a zone then add 'webpartpages:webpartzone' tag instead of 'asp:webpartzone' tag. you may add the additional functionality and events on code behind file. give a strong name to the project and build it.
Now we need a feature which will be used to deploy this page into mysite.

First create feature.xml file. open it in a editor and add the following-

< ?xml version="1.0" encoding="utf-8" ?>
< id="A28CE77C-7E79-49e1-867E-AF4280466BA7" title="custom pages for mysite" description="" xmlns="http://schemas.microsoft.com/sharepoint/" scope="Web" hidden="false" version="1.0.0.0">
<>
< location="element.xml">
< location="home.aspx">
< /elementmanifests>
< /feature>

Now Create element.xml file. Open it in an editor and add the following-

< ?xml version="1.0" encoding="utf-8" ?>
< xmlns="http://schemas.microsoft.com/sharepoint/">
< url="">
< url="home.aspx" name="home.aspx" type="Ghostable">
< /File>
< /Module>
< /Elements>

Now create a folder say- MySitePages. Put feature.xml,element.xml and home.aspx file into it. put this folder in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\ directory. Take the DLL of your ASP.Net application and put it into GAC.

Now we may use stsadm -o installfeature and stsadm -o activatefeature utility to deploy and activate the feature. we can activate the feature at site level after creating mysite.

After activating the page will be attached to the mySite.
Its done now. :)

1 comment:

  1. This is life saver for me, I was looking a good paper on customizing mysites in sharepoint.

    Thanks for posting.

    ReplyDelete