Archive

Posts Tagged ‘SharePoint 2010’

MySite Branding for SharePoint 2010

July 4th, 2011 Comments off

randing of MySites is always a challenging task. It was complicated in SharePoint 2007 and still confusing in SharePoint 2010. Recently we had a requirement to applying cooperate branding for MySites. I tried to find a reasonable solution but nothing was fitting well in the required scenario. So after completion I decided to share my idea with the world.

Before start applying new branding for MySites. We need to understand that MySites are actually use two different types of site collections. First you need a MySite host site collection and then each personal site is a separate site collection. So we have to apply branding on both sites.

Now come to the main task. There could be different ways to customise the MySites. But the best possible solution would be using feature stapling. If you are new to feature stapler you can see this good post from Chris (http://www.sharepointnutsandbolts.com/2007/05/feature-stapling.html).

So we need to create first feature with Site level scope. This feature will be called MySiteStaplee. This feature will deploy master pages to the site and also change the master page for the site. Right first step would be to create a new project in Visual Studio 2010 and create a feature with Site level scope. It will look like this.

MySite Stapler Project View
Now we need to attach an elements.xml to include the master pages to deploy through this feature. Now it is bit different in Visual Studio 2010. We need to add a module. Add master page in the module, and make changes in the elements.xml file as below.

<?xml version=”1.0″ encoding=”utf-8″?>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
<Module Name=”MasterPages” List=”116″ Url=”_catalogs/masterpage”>
<File Path=”MasterPages\salman.master” Url=”salman.master” Type=”GhostableInLibrary” />
</Module>
</Elements>

Your project will look like this now.

Now add a property to the master with a value as master name.

<?xml version=”1.0″ encoding=”utf-8″ ?>
<Feature xmlns=”http://schemas.microsoft.com/sharepoint/“>
<Properties>
<Property Key=”MySiteMasterPage” Value=”/_catalogs/masterpage/salman.master”/>
</Properties>
</Feature>

Next thing we need to add a feature event receiver to replace the master page for mysite. For this add feature event receiver with the MySiteStaplee. Your code for featureactivated will look like this.

/// <summary>
/// Key for MySite master.
/// </summary>
private const string MySiteMasterPage = “MySiteMasterPage”;

/// <summary>
/// Set master page on feature activation.
/// </summary>
/// <param>The SPFeatureReceiverProperties object.</param>
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;

if (site != null)
{
SPWeb web = site.RootWeb;
string oldMasterUrl = web.MasterUrl;

web = site.RootWeb;
string newMySiteMasterUrl = properties.Feature.Properties[MySiteMasterPage].Value;
if (!string.IsNullOrEmpty(newMySiteMasterUrl))
{
web.CustomMasterUrl = SPUrlUtility.CombineUrl(web.ServerRelativeUrl, newMySiteMasterUrl);
web.MasterUrl = SPUrlUtility.CombineUrl(web.ServerRelativeUrl, newMySiteMasterUrl);
}

web.Update();
}
}

Ok, so your staple feature is ready. Now you need a stapler to staple your feature with mysite site definition.
In order to achieve this create a new project. Create a new feature in this project with Farm level scope. It will look like this.

Now we need to staple the MySiteStaple with MySite host and MySite personal site definitions. So we need elements file here. Add a new Empty Element from Visual Studio 2010. Remember mysite host site definition’s template name is SPSMSITEHOST and MySite personal site template name is SPSPERS. Your elements file will look like this.

<?xml version=”1.0″ encoding=”utf-8″?>
<Elements xmlns=”http://schemas.microsoft.com/sharepoint/“>
<!– Feature to staple with MySite host site collection –>
<FeatureSiteTemplateAssociation TemplateName=”SPSMSITEHOST#0″ >
</FeatureSiteTemplateAssociation>
<!– Feature to staple with MySite personal site collection –>
<FeatureSiteTemplateAssociation TemplateName=”SPSPERS#0″ >
</FeatureSiteTemplateAssociation>
</Elements>

Ok so all is done. Now you have to deploy these wsp solutions to the server. This will apply your master page with MySite host and MySite personal site definitions. So whenever you create a new MySite host or whenever a user creates his/her MySite, this feature will replace the master page for the new site. Your final solution structure will look like this in visual studio 2010.

I hope it will help you start the branding. Please wait for my next post with the advance solution required for some more branding issues with MySites.

Cheers.

Add Links in SummaryLinksWebpart using PowerShell scripting

May 23rd, 2011 Comments off

More on the automation and adding data in other webparts. In previous post I talked about loading data in ContentEditorWebpart. Now look at SummaryLinkWebpart . Recently when i was working with SummaryLinkWebpart. I realised it is a bit different then other web parts to load links in summaryEditorWebpart. I looked for the internet but I couldn’t find any single example for SummaryLinksWebpart with power shell. So here is the example for others. I hope it will help some folks.

$webpart = new-object  $typeName
$webpartType = $webpart.GetType().ToString()

if($webpartType -eq “Microsoft.SharePoint.WebPartPages.ContentEditorWebPart”)
{
        if($values)
       {
               $keyValuePairs = $values.split(“,”)
               foreach ($keyValuePair in $keyValuePairs)
              {
                       $keyValueArray = $keyValuePair.Split(“|”)

                       [string]$propertyName = $keyValueArray[0].Trim()
                       [string]$propertyValue = $keyValueArray[1].Trim()

                       $sumLink = New-Object Microsoft.SharePoint.Publishing.SummaryLink $propertyName
                       $sumLink.LinkUrl = $propertyValue
                       $webpart.SummaryLinkValue.SummaryLinks.Add($sumLink)
                       $webpart.SummaryLinkValue = $webpart.SummaryLinkValue
              }
       }
}

Cheers

Load data in ContentEditorWebpart using PowerShell scripting

May 23rd, 2011 Comments off

If you are working on SharePoint content automation then powershell scripts are the most talked item. But sometime it is very difficult to find the right way to load data in web parts. For different web parts you have to treat differently. Here is the example to load data in ContentEditorWebpart.
I have a powershell function, where I’m passing some values including web part type and HtmlContent. HtmlContent is the text I want to set in ContentEditorWebpart.

$webpart = new-object  $typeName
$webpartType = $webpart.GetType().ToString()

if($webpartType -eq “Microsoft.SharePoint.WebPartPages.ContentEditorWebPart”)
{
        if($HtmlContent)
       {
              [string]$content = $HtmlContent.ToString()
              $docXml = New-Object System.Xml.XmlDocument
              $contentXml = $docXml.CreateElement(“Content”)
              $contentXml.set_InnerText($content)
              $docXml.AppendChild($contentXml)

              $webpart.Content = $contentXml
       }
}

I hope it will help.

Cheers

Hide the ‘Pages’ library in SharePoint breadcrumb

May 11th, 2011 Comments off

SharePoint breadcrumb is a nice feature to have on the pages. But it doesn’t fit very easily in usual scenario. If you also want to get rid of ‘Pages’ library link in the breadcrumb of a publishing site then see the below instructions.

Normal breadcrumb

My Portal -> Pages -> Test Page1

Updated breadcrumb

My Portal -> Test Page1

Then change the breadcrump source provide to CurrentNavSiteMapProviderNoEncode.  You have to change this in SiteMapPath tag like this…..

<asp:SiteMapPath SiteMapProvider=”CurrentNavSiteMapProviderNoEncode” id=”ContentMap” SkipLinkText=”" NodeStyle-CssClass=“ms-sitemapdirectional runat=“server”/>

 Now when we use CurrentNavSiteMapProviderNoEncode, we have to make sure that ‘Show Pages’ is true for current navigation. Even if you don’t want to display pages on the left navigation you have to enable it. Then you can hide your pages one by one from the navigation settings.

Cheers

Create Item Workflow – SharePoint Designer 2010

May 30th, 2010 Comments off

Sometime you have to create a new list item in a different list on the list item changed or list item created events. It can be to create an announcement on a list item created or changed. In these cases you also like to use the originator list item properties in new list item.
In order to create this workflow using SharePoint Designer 2010 we will use the same approach as in my previous blog. We just do changes in the workflow Action. So create a new workflow CreateItems in SharePoint Designer 2010. You can find more help on creating workflows using SharePoint Designer 2010 here.

For this demonstration I will create a workflow which creates an item in a list name ParentList on item created and item changed of Announcements list. For this I created three new fields in custom list ParentList. These columns names are listName, ItemGuid and ItemTitle. All these are single line fields. And we will assign values in these columns through workflow.
Open Action in the top ribbon of the workflow setting screen in SharePoint Designer 2010. Select Create List Item option. It will create a standard statement for Create List Item Action. Now click on this list and select ParentList.
Click on the ListName in fields and select modify. Add value Announcements as list name. Then add a new field for column ListItem. For value select the function button (fx) and then select the Current Item in Data source and select the GUID in Field from source. Click Ok finally.

Add another field for ItemTitle column and select the Current Item and Title instaed of GUID.

It will actually tell workflow to assign these values to newly created item. In this case it is assigning the Announcements list item GUID and title to new item. Also we added Announcements as a text for ListName here.

Now save the workflow and then from workflows setting screen change the Start Options. Select the list item created and list item changed there. After doing all these settings just publsih it.

Once this workflow is deployed on the site, open the site and add new item in Announcements list. It will create a new item in ParentList and assign Announcements list item GUID and title to the specified fields of newly created ParentList item.

Isn’t this very simple and cool

Have fun.

Copy Item Workflow using SharePoint Designer 2010

May 30th, 2010 15 comments

SharePoint Designer 2010 comes with huge improvements in its features. One of the very amazing improvements is designer’s workflows.

Today I’m going to create a list item workflow in SharePoint Designer 2010. This is a simple workflow that you create in several cases. For this demonstration I have created a TeamSite. You can create this workflow for any site.

What we will achieve from this workflow

I have a default announcement list. And then I created another list with the name CopiedAnnouncement with announcement list template. Now I want to create a workflow for announcement list so when I create or change an item in announcement list it will copy the item in CopiedAnnouncement list. Both the lists are identical in structure.

Also I edited my site’s home page to display both lists. For this
Click on Edit Page under Site Actions
Click on Insert under Editing Tools
Select Existing List
Select Announcements and CopiedAnnouncements one by one.

Purpose of displaying lists on the same page is just to see workflows result quickly.

Now come to the main task, and open your site in SharePoint Designer 2010. In order to create a new workflow, click on File menu and select Add Item. Then select the List Workflow under Workflows tab.

Add CopyItem as the name of new workflow. And select the Announcements in the list drop down. Your new workflow will be attached to the selected list.

When ypu click on Create, it will show a popup message to download data for workflow.

Once it completes the downlaod and load the workflow page. Then click on Edit Workflow link.

Now on this screen you can add Conditions and Actions for your workflow. My workflow is very simple and not using any condition so I will just add as Action straight away. Click on the Action from the top ribbon and then select the Copy List Item.

It will create a standard Copy List item Action.

Now select the Current Item for first option and select CopiedAnnouncements for second option. It is pretty straight forward that this action is saying to copy the current list item to selected list.

Now Click on the Save, it will show a save progress message.

Now choose the Start Option. There are three options to trigger a workflow. Start manually, on List Item Created and on List Item Changed. In my case I selected for List item Created. You can find these options under Start Options on the main workflow setting screen.

Now click on the Publish from the top ribbon. This will deploy the workflow on the site and also attached it to the already selected list. Making life easy. When your workflow is deployed, you can verify it by looking into the list workflow setting. CopyItem should be visible there and will show 0 numbers of workflows running at this stage.

Now it is the time to see workflow in action. In order to test the workflow add new item in announcements list. When we add a new item in list it will trigger the workflow to copy the item in CopiedAnnonucements list.

After adding new item in the Announcements list, you just have to refresh the page. Give 5 to 10 seconds to workflows to trigger and then refresh the page. You can see the item copied it the CopiedAnnonucements list.

Thats All, your workflow is ready and working what was expected.

Cheers

SharePoint 2010 Release date announced

March 5th, 2010 Comments off

Yes finally SharePoint 2010 release date is announced. It is 12 May 2010 at 11:00 am. For more details Click here

Categories: SharePoint 2010 Tags:

Customization of SharePoint 2010 navigation – publishing site

February 12th, 2010 2 comments

In my previous blog, I customized the SharePoint 2010 publishing site. Now I will give you some idea that how you can create customize the navigation according to new look and feel. There are different ways to customize the navigation of SharePoint. I like to use a custom control which returns navigation in the form of xml and then I transform it from xsl. In this way you can easily control the output of the navigation or any other control.  

<SafeControl Assembly=SalmanSPControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=49908bd985021621 Namespace=SalmanSPControls TypeName=* Safe=True />You need to add a reference in your SharePoint master page. It would be like this. 

<% @ Register Tagprefix=”SWC” Namespace=”SalmanSPControls” Assembly=”SalmanSPControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=49908bd985021621″ %>  

Then I created a class for navigation inherited from ASP .Net Menu and xml based control class. This class is not doing much but just adding all the items in xml. It’s getting these items from Menu items. In the master page when you use this control you need to specify the data source id. If you search in your master page you can find a tag like this.  

<PublishingNavigation:PortalSiteMapDataSource EnableViewState=”false” ID=”leftNavDataSource” Runat=”server” SiteMapProvider=”CombinedNavSiteMapProvider” StartFromCurrentNode=”true” StartingNodeOffset=”1″ ShowStartingNode=”true” TreatStartingNodeAsCurrent=”true” TrimNonCurrentTypes=”Heading” />  

There will be two tags like above one for global navigation and other for current navigation. For left navigation you have to look the current navigation site map data source. In portal site map data source you can also change the SiteMapProvider, depending on your needs. You can use the current or combine or global. These site map providers are defined in web.config. You can find the difference of these site map providers in SharePoint documentation.
Now you have to replace the existing navigation control with your new custom navigation control. After that your master page changes are over. Now your control is ready and will display instead of default SharePoint current navigation. Here is how your navigation control will look like.  

<SWC:Navigation cacheperpage=”true” EnableViewstate=”false” ID=”LeftNav” Runat=”server” DataSourceID=”leftNavDataSource” Transform-XslName=”leftnav.xsl” Transform-CacheOutput=”false”/> 
 
But this control is just returning xml. You need to transform it in an html through some xsl. For this I created one xsl file and use some style classes to give it new look.  Here is the piece of code I use in my xsl to transform navigation xml into new look. 
 
<xsl:template match=”/>
    <xsl:if test=count(Navigation/Item) &gt; 0>
        <div id=nav-y>
             <p>
                 <a href={Navigation/Item/@Url}title=”{Navigation/Item/@Title}>
                      <xsl:value-of select=”Navigation/Item/@Titledisable-output-escaping=”yes/>
                 </a>
             </p>
             <ul>
                 <xsl:apply-templates select=”Navigation/Item>
                     <xsl:with-param name=”levelselect=”1/>
                     <xsl:with-param select=”@Titlename=”sectionTitle/>
                 </xsl:apply-templates>
              </ul>
        </div>
    </xsl:if>
 </xsl:template>
 
<xsl:template match=”Item“>
    <xsl:param name=”level” />
    <xsl:param name=”sectionTitle” />
    <xsl:choose>
        <xsl:when test=”$level != 1“>
            <li>
                <xsl:if test=”@Selected=’True’ or @Current=’True“>
                    <xsl:attribute name=”class“>Selected</xsl:attribute>
                </xsl:if>
                <a href=”{@Url}title=”{@Title}“>
                    <xsl:value-of select=”@Titledisable-output-escaping=”yes“/>
                </a>
                <xsl:if test=”count(Item) &gt; 0 and @Current = ‘True“>
                    <ul>
                        <xsl:apply-templates select=”Item“>
                            <xsl:with-param name=”levelselect=”$level + 1” />
                            <xsl:with-param select=”@Titlename=”sectionTitle” />
                        </xsl:apply-templates>
                    </ul>
                </xsl:if>
            </li>
        </xsl:when>
        <xsl:otherwise>
            <xsl:apply-templates select=”Item“>
                <xsl:with-param name=”levelselect=”$level + 1” />
                <xsl:with-param select=”@Titlename=”sectionTitle” />
            </xsl:apply-templates>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>
 
 So now after doing all these changes my new site will look like this.
  
   

Hope you enjoyed customization of SharePoint 2010 navigation in publishing sites.  

Cheers

Branding of SharePoint 2010 publishing site

February 8th, 2010 Comments off

Couple of days ago, I was thinking to look the customization of new SharePoint 2010 publishing site. Here are the steps I took to achieve this goal. When you create a basic SharePoint publishing site, it looks like this.

As you people now that SharePoint websites are based on master-pages, and previously when we had to achieve branding in SharePoint 2007. We used minimal master page and then our own styling for it. I was thinking the same way that how I can get a minimal master page for SharePoint 2010. By the way if you look in the master pages library there is a master page named minimal.master. This page is a simple master page without navigation and much of the controls. It is a default master page for search pages. Anyhow the new term for minimal master page in SharePoint 2010 is starter page. Thanks to MSDN and Randy Drisgill, this starter page is available on CodePlex and MSDN. I picked the one from CodePlex and use the _starter.master. It is very well commented and easy to understand.

I have done the changes for html in master page for new look. For my style sheet I added a reference like this.

<SharePoint:CssRegistration name=“/Style Library/Styles/styles.css” After=“corev4.css” runat=“server”/>

If you want to do any change in the global (top) navigation or current (left) navigation you can do it from the SharePoint settings page. For this purpose you can select ‘Modify Navigation’ from the ‘Site Actions’ menu.

This is how it looks after the customization.

In next post I will talkabout creating custom controls for SharePoint 2010 publishing sites.

Develop, Deploy and Debug Sandboxed Solutions

December 18th, 2009 4 comments

Sandboxed solution in SharePoint 2010 is a new way of deployment for rapid development. You can deploy your solutions on site collections without resetting the farm. Sandboxed solutions are per site collection. You can create them like the normal farm solutions. You can see the detailed information about sandbox solutions here.

Develop SandBoxed Solution

 In Visual studio 2010 there is a lot of support for SharePoint projects. Whenever you start a new SharePoint project (except a few options) it will ask you about the solution type in second window. By default sandboxed solution is selected as solution type.

Select Deployment type

You can also change the deployment type at any time from the project properties window.

Change Solution Deployment type

In a SharePoint solution you can have assemblies, features, Web Parts, list definitions and feature receivers. Now if you want to add a Web Part in this solution, right click on the solution and select add new item.

Add new item

Select Web Part from the available option. In Sandboxed solutions you cannot use Visual Web Part. Actually from sandboxed solution you can deploy files to web front-end server. Visual web part deploys visual files to server. So you can use the simple Web Part from the option. If you select Visual Web part, you will notice that sandboxed solution option will be grayed-out in next screen, where you define deployment type.

Select Web Part

Now you can start writing your code for web part. I have added a snap-shot of sample code.

Code

It’s a simple piece of code, accessing a list from the site collection and displaying items in a ListBox control. In sandboxed solutions you can access all the classes under SPSite, SPWeb, SPList, and SPListItem. Sandboxed solutions deploy as partial-trust solutions, so there are some limitations. You cannot use classes other than mention above. For example you cannot use code for run with elevated privileges block. If you try to use classes outside the scope of sandboxed solution you won’t get IntelliSense from Visual Studio. If use SPSecurity.RunWithElevatedPrivileges it will compile without any error message. It is because of the fact that visual studio compile against the full API of the SharePoint. Visual studio helps to write code specific for sandboxed solution by providing proper IntelliSense for available classes. But if you use code from a full-trust solution, there is no way to detect error in visual studio. You can only see exception when this code execute in sandboxed process. The exception thrown is “Could not load type ‘CodeToRunElevated’.

Use SPSecurity Error

When your build is successful, you can create a wsp file. In visual studio 2010, create a wsp is very simple. Previously it was another painful task to create wsp file. You had to use different ways to create a cab file and then rename it with extension wsp.  Now you can right click on the solution and select ‘Package’ option. It will create a wsp file for current solution in bin/Debug folder.

Create wsp solution
Deploy Sandboxed solutions
Deployment of sandboxed solution is very simple and rapid. You just have to upload your solution in a library name solutions. Every site collection in SharePoint 2010 has a solutions library. You can see more details about solution library here. Solutions library is a SharePoint list. When you upload your solution it will prompt to activate it.  If you like to upload a solution, better way to open the solution files in visual studio and then after the changes build and create a new solution. Now deactivate old solution from the solutions library and upload new solution. Finally activate it. Your solution is now deployed including the web part. Here you can also see that how you can use your custom web part in SharePoint pages. Click here

Debug Sandboxed solution
We know that SharePoint sites runs under the IIS worker process w3wp.exe. In order to debug SharePoint sites we attach our code to w3wp.exe process. But sandboxed solutions run under a different process Sandboxed worker process (SPUCWorkerProcess.exe).  so if you want to debug your code in sandbox solution you have to attach your code to SPUCWorkerProcess.exe and if you like to debug rest of the page then you have to attach it to w3wp.exe process.

Task manager view

I hope it will be helpful, I will try to explore more in coming days and will share again.