Subscribe: SharePoint SharePoint SharePoint

Thursday, January 30, 2014

Web Part cannot be imported.It's is not registered as safe

While trying to add a custom web part in SharePoint we might come across an error like :

"A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe"

SharePoint 2013



This happens when safe control entries are set to false.

This behavior can be corrected in two ways:

1. Adding safe entries in web.config file :

  a. Open web.config
  b. Locate the SafeControls Tag
  c. Make a safe control entry

    <SafeControl Assembly="Assembly name, Version=1.0.0.0, Culture=neutral,    PublicKeyToken=d8eb6481d8b4beec" Namespace="your webpart namespace" TypeName="*" Safe="True" />

2. Adding safe entries  in SharePointProjectItem.spdata file which can be found in your project    folder: Project Folder-> Module ->spdata file.

 <SafeControl Assembly="Assembly name, Version=1.0.0.0, Culture=neutral,    PublicKeyToken=d8eb6481d8b4beec" Namespace="your webpart namespace" TypeName="*" Safe="True"  />

In some cases the issue is resolved by following any one of them while in other cases both of these methods need to be implemented.

Wednesday, January 29, 2014

Migrating Managed Metadata Term Stores in SharePoint Server across Farms

While moving a site from development environment to production environment, it is recommended to move MMS term stores too. We can actually adopt two approaches to this:

1. Export Term Stores in a .csv file and then Import them to target server.
2. Use a powershell script to create a .cab file to import on target server.

SharePoint

The first approach is easier but has a major drawback. It does not persist the GUID of the terms. This may lead to many errors in the imported site because some web parts might be dependent on a term's guid.

e.g. if i have a CQWP which shows filtered data as per a MMS term, then in the target server the filtering would be lost.

So a better and safe way is to export and import MMS using Powershell:

Export

SharePoint

 Add-PSSnapin Microsoft.SharePoint.Powershell
 $metadataApp= Get-SpServiceApplication | ? {$_.TypeName -eq "Managed Metadata Service"}
 $mmsAppId = $metadataApp.Id

 $mmsproxy = Get-SPServiceApplicationProxy | ?{$_.TypeName -eq "Managed Metadata Service Connection"}
 Export-SPMetadataWebServicePartitionData -Identity $mmsAppId -ServiceProxy $mmsproxy -Path "C:\Users\Desktop\MMD.cab”

Import


SharePoint

Add-PSSnapin Microsoft.SharePoint.Powershell
 $metadataApp= Get-SpServiceApplication | ? {$_.TypeName -eq "Managed Metadata Service"}
 $mmsAppId = $metadataApp.Id

 $mmsproxy = Get-SPServiceApplicationProxy | ?{$_.TypeName -eq "Managed Metadata Service Connection"}

Import-SPMetadataWebServicePartitionData -Identity $mmsAppId -ServiceProxy $mmsproxy -Path "//SharedPath/Users/Desktop/MMD.cab" -OverwriteExisting;

NOTE: While importing make sure the .cab file is in a network path accessible to SQL Server with ContentDB and which has been shared with the user account of the MMS Service.

Problems Adding Apps in SharePoint 2013

Sometimes adding an app in SharePoint 2013 does not work. It throws an error "Sorry,something went wrong". This can happen due to a lot of reasons. But when i ran through this problem it was because of using a custom master page.




My custom master page did not have a "Breadcrumb" content placeholder (PlaceHolderTitleBreadcrumb) But "adding apps" expected that content placeholder. So after adding it the problem was resolved.

Make sure you have all placeholders as below:

1. DeltaPlaceHolderLeftNavBar
2. PlaceHolderLeftNavBar
3. DeltaPlaceHolderPageTitleInTitleArea
4.  PlaceHolderPageTitleInTitleArea 

Also each of them should not be set to Visible=False


The code for the content placeholders are:

<SharePoint:AjaxDelta id="DeltaPlaceHolderLeftNavBar" BlockElement="true" runat="server">
<asp:ContentPlaceHolder id="PlaceHolderLeftNavBar" runat="server">
</asp:ContentPlaceHolder>
</SharePoint:AjaxDelta
<SharePoint:AjaxDelta id="DeltaPlaceHolderPageTitleInTitleArea" runat="server">
<asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea" runat="server">
</asp:ContentPlaceHolder><asp:ContentPlaceHolder id="PlaceHolderTitleBreadcrumb" runat="server" Visible="false"></asp:ContentPlaceHolder>
</SharePoint:AjaxDelta>