SharePoint 2010: how to import/export metadata terms

Using PowerShell script to achieve this

  • Service account required to have BULKAdmin permission in SQL database, otherwise it will be having exception: You do not have permission to use the bulk load statement
  • Make sure the service account will have the permission to access to the file path, otherwise it will be having exception:  Access to the path ‘C:\Temp’ is denied.

Here is the PowerShell Script to Import and Export terms:

#Update these according to what is created/shown in central administration

$proxyName = “Managed Metadata Service”
$serviceName = “Managed Metadata Service”
$filePath = “C:\Temp\terms.bak”

#Get the Metadata Service Application

$svc = Get-SPServiceApplication | ?{$_.TypeName -eq “Managed Metadata Service” -and $_.DisplayName -eq $serviceName}

#Use this to Export

Export-SPMetadataWebServicePartitionData $svc.Id -ServiceProxy $proxyName -Path $filePath

#Use this to Import

Import-SPMetadataWebServicePartitionData $svc.Id -ServiceProxy $proxyName -Path $filePath -OverwriteExisting

This only works in a single farm , all in one box solution, there will be issues coming up when it’s a multi-server situation.

You will get the following exception if that’s the case:

Cannot bulk load because the file “C:\Temp\terms.bak” could not be opened.

The workaround for this is:

  1. copy the terms.bak to the SQL server box,  and grant read and write permission with the service account in that folder temporarily
  2. Replace the file path to use a network path, for example “\\servername\c$\temp\terms.bak”
Advertisements

SharePoint 2010: Why is my custom Content Query Web Parts not working on other site collections?

Scenario:

When we are working on the custom content query web parts, we always have our own xsl files, in order to apply these custom styles into our custom content query web parts, we need to change one-three of the properties to get it working, it would be

  1. HeaderXslLink
  2. MainXslLink
  3. ItemXslLink

So when you change the property of one of the following, let’s say ItemXslLink

<property name=”ItemXslLink” type=”string”>/Style Library/Xsl Style Sheets/CustomItemStyle.xsl</property>

It will works fine as long as that location/root site collection exist, but what happen is when you only deploy to a site collection which is not the root one, and the solutions didn’t get deploy to the root site collection?

In order to fix this issue:

  1. Modify the link to something like ~siteCollection/Style Library/Xsl Style Sheets/CustomItemStyle.xsl
  2. Add a event receiver for the feature activation
  3. Loop through all the custom web parts files and replace the “~siteCollection” hat with the current site ServerRelativeUrl

This will fix the web parts reference in some similar scenarios when you cannot import the web part

SharePoint 2010: How to pass Web Part Properties into xslt style sheet

There are three files that need to be modified in order to pass the web part properties into the xslt item styles sheet

  1. Your web part file, name.webpart
  2. content query main xslt style, ContentQueryMain.xsl
  3. item style xslt style, ItemStyle.xsl
  4. You can have these file in a custom one with different names just need to remember to update your web part file to point the custom files

So we need to do the following in each of the file in order to get the web part property to show in the xslt item style,

For example:

We want to pass the web part url and display a header in the xslt style sheet when the row count is 1, which is the first row

1. In the webpart file, You will need to add/change the web part property ParameterBindings as the following:

<property name=”ParameterBindings” type=”string”>

&lt;ParameterBinding Name=”WebPartTitle” Location=”WPProperty(Title)”/&gt;

</property>

*notes that binding property name WebPartTitle is what we need to use the same in the style sheet

 

2. You need to add a parameter in ContentQueryMain.xsl

<xsl:param name=”WebPartTitle” />

*note: this parameter name needs to be same as what is specified in the web part file

And modify the template OuterTemplate.CallTemplate to pass the param in ItemStyle to something similar as the following:

Let’s say you want to only pass into the style call “News”

Add a choose statement

<xsl:choose>

<xsl:when test=”@Style=’News'”>

<xsl:with-param name=”WPTitle” select=”$WebPartTitle” />

</xsl:when>

</xsl:choose>

*note: WPTitle is the param name you wanted to use in the itemstyle, WebPartTitle is what is passed in from the webpart file

 

3. In the itemstyle you need to do the following to read the value pass in:

Add the following in the front of the style,

<xsl:param name=”wpTitle” />

note: this is what we passed in from the content query main

Then you can display it with the format you want, for example:

<xsl:value-of select=”$wpTitle” />

SharePoint 2010: How to use jQuery to update the TaxonomyFieldControl field values

  • To update the visual display of the taxonomy textbox
  1. target the .ms-taxonomy-writeableregion
  2. update  the html markup with specific format per item: “<span class=”valid-text” title=””>{0}</span>”, 0: name of the taxonomy term
  3. update the hidden value in the page, so it will save to the page field
  4. target the INPUT.ms-taxonomy class with specific format: “{0}|{1};” with the 0: name of the taxonomy term, 1: GUID of the taxonomy term.

Scenario:
This is useful when the user don’t want to struggle with the enterprise keywords intellisense since they don’t know about the structure of the term set, therefore we can make a custom tree view / check box list for the user to pick from and update the UI on the client side, to fill up the field when user pick an option.

SharePoint 2010: How to pass query string in SharePoint modal dialog

Scenario:

Usually we open the modal dialog like the following in client side code:

var option = { url:””, title:””, width:””, height:””, dialogReturnResultCallBack: closeFunction }

SP.UI.ModalDialog.showModalDialog(options);

By using this way to open the modal dialog, you won’t be able to pass in additional query string in the url\

Modal Dialog Reference

http://msdn.microsoft.com/en-us/library/ff410058(v=office.14).aspx

 

Solution:

We could use SP.UI.ModalDialog.OpenPopUpPage method

SP.UI.ModalDialog.OpenPopUpPage(url, callback, width, height);

By using this method we can pass in the query string by adding into the url,

for example: http://site/pages/default.aspx?q=1&text=2

Microsoft OpenPopUpPage  reference

http://msdn.microsoft.com/en-us/library/ff410825(v=office.14).aspx

SharePoint: How to get visual web parts embed into page layouts

  • Add the register to top of the page layout

<%@ Register tagprefix=”Prefix” namespace=”Assembly namespace” assembly=”Assembly info” %>

  • Uses the web part in the page layouts as other normal asp controls

<Prefix:Name ID=”ID” runat=”server” …. />

Example:

In the Register Section add the following:

<%@ Register tagprefix=”Custom” namespace=”CustomWebParts” assembly=”CustomWebparts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1234567890123456″ %>

In the Page content add the following:

<Custom:WebPartName ID=”ID” runat=”server” otherProp=”prop” />