This Blog Represents the Steps to connect sitecore 9.1 with sharepoint 2007 and above for both on premesis server and sharepoint online feature which is available on the outllook 365 .
To do the migration first you should have a sitecore 9.1 instance installed . You can get the details from https://dev.sitecore.net/Downloads/Sitecore_Experience_Platform/91/Sitecore_Experience_Platform_91_Initial_Release.aspx .
First step of migration will be the installation of package , so already there is a package available compatible upto Sitecore 8.2 version from https://dev.sitecore.net/Downloads/SharePoint_Connect.aspx , but sitecore 9.1 does not supports these connectors , so i did some modifications in the existing package and also made some changes in the config files and it worked like a charm.
The connector Package is available here https://drive.google.com/file/d/1Njfvd3Xbr-2WC5kICIEXYRta1CAXmmGo/view.
Open the Sitecore instance open the launchpad and Go to Control Panel > Install A Package > Upload Package , and upload the package .
After that You have to deploy some files into your instance , you can get those from here https://drive.google.com/file/d/1mKEPzyIipB2OWc_PNi5b6wiQB9ySYQrA/view , one by one using the same folder structure in sitecore .
If you get an error stating
The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0
You must add
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
under the assembles node in Web.Config .
Note:-
You must also add Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll Version 15+ , in the bin folder to avoid errors.
At Last Open the Sitecore.Sharepoint.config File and add your connection configuration here
<server url="https://SharePointURL" username="user" password="password" connectionConfiguration="Default" context="Any"/>
Default is using the Windows Authentication mode , but you can change this here or using the integration Wizard also.
The code is present in the https://github.com/Sitecore/SharePoint-Connect.
My Findings -
While migrating the content the issues i have faced till now .
1. The Lookups did not get imported correctly as the connector only imports the text , and date fields , the list fields are not imported , instead it appears like this format
Executive actions;#1;#Law and policy updates;#2;#Travel updates;#5;#Nonimmigrant status;#6;#Immigrant status;#7;#Reports and notices;#4
The #{Number} shows the List Item ID from the sharepoint .
To solve this insead of using the Template created by sharepoint connector create your generic tempate will all the sharepoint fields you need , and you can change this from here
ID templateID = this.CreateTemplate();
in the IntegrationWizardForm.cs in the Sitecore.Sharepoint.Web , which you can get from the above github link.
Then also in the Multilist field you will get the same result as it was in the text field , so to get the appropriate results , i searched the item from the names after formating it correctly , and added the item ids in the raw values of the field.
To do this create a event action method and call it on item:saved.
Create a index in solr which is has the same datasource as the items same as the multilist have .
Config:
<events>
<event name="item:saved">
<handler type="Domain.FillMultilistEvent, Domain" method="OnItemSaved"/>
</event>
</events>
Code:
public class FillMultilistEvent
{
public virtual void OnItemSaved(object sender, EventArgs eventArgs)
{
Item ItemSaved = Event.ExtractParameter(eventArgs, 0) as Item;
if (ItemSaved != null && ItemSaved.TemplateID.ToString() == TemplateConstants.BlogPreviewTemplate)
{
if ( ItemSaved.Fields["Category"] != null && !ItemSaved.Fields["Category"].Value.Contains("{"))
{
using (new SecurityDisabler())
{
ItemSaved.Editing.BeginEdit();
GetCategories(ItemSaved);
ItemSaved.Editing.EndEdit();
}
}
}
}
public static void GetCategories(Item ItemSaved)
{
string RawCategoryFieldValue = ItemSaved.Fields["Category"].Value;
string FilteredCategories = string.Format("{0}", Regex.Replace(RawCategoryFieldValue, @"\d", "").Replace("#", "").Replace(";;", ";"));
List<string> Categories = new List<string>();
Categories = FilteredCategories.Split(';').ToList();
ItemSaved.Fields["Category"].Value = "";
foreach (var subcategory in Categories)
{
if (!string.IsNullOrEmpty(subcategory))
{
using (var context = ContentSearchManager.GetIndex("blog_categories_index").CreateSearchContext(SearchSecurityOptions.DisableSecurityCheck))
{
var queryableResultItems = context.GetQueryable<GlobalSearchResultItem>()
.Where(x => x.Language.Equals(Sitecore.Context.Language.Name, StringComparison.InvariantCultureIgnoreCase));
queryableResultItems =
queryableResultItems.Where(
GetTemplatesFilterPredicate(TemplateConstants.BlogSubcategoryTemplateID.ToGuid()));
queryableResultItems = queryableResultItems.Where(GetSearchPredicateCategory(subcategory));
var searchResult = queryableResultItems.GetResults();
var listResult = searchResult.Hits.Select(hit => hit.Document).ToList();
if (listResult.Count > 0 && searchResult.TotalSearchResults > 0)
{
ItemSaved.Fields["Category"].Value += listResult.First().ItemId.ToString() + "|";
}
}
}
}
if (ItemSaved.Fields["Category"].Value.Length > 0)
{
ItemSaved.Fields["Category"].Value = ItemSaved.Fields["Category"].Value.Remove(ItemSaved.Fields["Category"].Value.Length - 1, 1);
}
}
private static Expression<Func<GlobalSearchResultItem, bool>> GetTemplatesFilterPredicate(Guid includeTemplate)
{
Expression<Func<GlobalSearchResultItem, bool>> filterSearch = x => true;
if (includeTemplate == Guid.Empty) return filterSearch;
filterSearch = filterSearch.Or(x => x.TemplateId == includeTemplate.ToID());
return filterSearch;
}
private static Expression<Func<GlobalSearchResultItem, bool>> GetSearchPredicateCategory(string SearchRequest)
{
Expression<Func<GlobalSearchResultItem, bool>> filterSearch = x => true;
if (SearchRequest == null) return filterSearch;
filterSearch = filterSearch.Or(x => x.DisplayName.Contains(SearchRequest));
Expression<Func<GlobalSearchResultItem, bool>> filterSearchText = x => true;
filterSearch = filterSearch.And(filterSearchText);
return filterSearch;
}
}
To do the migration first you should have a sitecore 9.1 instance installed . You can get the details from https://dev.sitecore.net/Downloads/Sitecore_Experience_Platform/91/Sitecore_Experience_Platform_91_Initial_Release.aspx .
First step of migration will be the installation of package , so already there is a package available compatible upto Sitecore 8.2 version from https://dev.sitecore.net/Downloads/SharePoint_Connect.aspx , but sitecore 9.1 does not supports these connectors , so i did some modifications in the existing package and also made some changes in the config files and it worked like a charm.
The connector Package is available here https://drive.google.com/file/d/1Njfvd3Xbr-2WC5kICIEXYRta1CAXmmGo/view.
Open the Sitecore instance open the launchpad and Go to Control Panel > Install A Package > Upload Package , and upload the package .
After that You have to deploy some files into your instance , you can get those from here https://drive.google.com/file/d/1mKEPzyIipB2OWc_PNi5b6wiQB9ySYQrA/view , one by one using the same folder structure in sitecore .
If you get an error stating
The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0
You must add
<add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
under the assembles node in Web.Config .
Note:-
You must also add Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll Version 15+ , in the bin folder to avoid errors.
At Last Open the Sitecore.Sharepoint.config File and add your connection configuration here
<server url="https://SharePointURL" username="user" password="password" connectionConfiguration="Default" context="Any"/>
Default is using the Windows Authentication mode , but you can change this here or using the integration Wizard also.
The code is present in the https://github.com/Sitecore/SharePoint-Connect.
My Findings -
While migrating the content the issues i have faced till now .
1. The Lookups did not get imported correctly as the connector only imports the text , and date fields , the list fields are not imported , instead it appears like this format
Executive actions;#1;#Law and policy updates;#2;#Travel updates;#5;#Nonimmigrant status;#6;#Immigrant status;#7;#Reports and notices;#4
The #{Number} shows the List Item ID from the sharepoint .
To solve this insead of using the Template created by sharepoint connector create your generic tempate will all the sharepoint fields you need , and you can change this from here
ID templateID = this.CreateTemplate();
in the IntegrationWizardForm.cs in the Sitecore.Sharepoint.Web , which you can get from the above github link.
Then also in the Multilist field you will get the same result as it was in the text field , so to get the appropriate results , i searched the item from the names after formating it correctly , and added the item ids in the raw values of the field.
To do this create a event action method and call it on item:saved.
Create a index in solr which is has the same datasource as the items same as the multilist have .
Config:
<events>
<event name="item:saved">
<handler type="Domain.FillMultilistEvent, Domain" method="OnItemSaved"/>
</event>
</events>
Code:
public class FillMultilistEvent
{
public virtual void OnItemSaved(object sender, EventArgs eventArgs)
{
Item ItemSaved = Event.ExtractParameter(eventArgs, 0) as Item;
if (ItemSaved != null && ItemSaved.TemplateID.ToString() == TemplateConstants.BlogPreviewTemplate)
{
if ( ItemSaved.Fields["Category"] != null && !ItemSaved.Fields["Category"].Value.Contains("{"))
{
using (new SecurityDisabler())
{
ItemSaved.Editing.BeginEdit();
GetCategories(ItemSaved);
ItemSaved.Editing.EndEdit();
}
}
}
}
public static void GetCategories(Item ItemSaved)
{
string RawCategoryFieldValue = ItemSaved.Fields["Category"].Value;
string FilteredCategories = string.Format("{0}", Regex.Replace(RawCategoryFieldValue, @"\d", "").Replace("#", "").Replace(";;", ";"));
List<string> Categories = new List<string>();
Categories = FilteredCategories.Split(';').ToList();
ItemSaved.Fields["Category"].Value = "";
foreach (var subcategory in Categories)
{
if (!string.IsNullOrEmpty(subcategory))
{
using (var context = ContentSearchManager.GetIndex("blog_categories_index").CreateSearchContext(SearchSecurityOptions.DisableSecurityCheck))
{
var queryableResultItems = context.GetQueryable<GlobalSearchResultItem>()
.Where(x => x.Language.Equals(Sitecore.Context.Language.Name, StringComparison.InvariantCultureIgnoreCase));
queryableResultItems =
queryableResultItems.Where(
GetTemplatesFilterPredicate(TemplateConstants.BlogSubcategoryTemplateID.ToGuid()));
queryableResultItems = queryableResultItems.Where(GetSearchPredicateCategory(subcategory));
var searchResult = queryableResultItems.GetResults();
var listResult = searchResult.Hits.Select(hit => hit.Document).ToList();
if (listResult.Count > 0 && searchResult.TotalSearchResults > 0)
{
ItemSaved.Fields["Category"].Value += listResult.First().ItemId.ToString() + "|";
}
}
}
}
if (ItemSaved.Fields["Category"].Value.Length > 0)
{
ItemSaved.Fields["Category"].Value = ItemSaved.Fields["Category"].Value.Remove(ItemSaved.Fields["Category"].Value.Length - 1, 1);
}
}
private static Expression<Func<GlobalSearchResultItem, bool>> GetTemplatesFilterPredicate(Guid includeTemplate)
{
Expression<Func<GlobalSearchResultItem, bool>> filterSearch = x => true;
if (includeTemplate == Guid.Empty) return filterSearch;
filterSearch = filterSearch.Or(x => x.TemplateId == includeTemplate.ToID());
return filterSearch;
}
private static Expression<Func<GlobalSearchResultItem, bool>> GetSearchPredicateCategory(string SearchRequest)
{
Expression<Func<GlobalSearchResultItem, bool>> filterSearch = x => true;
if (SearchRequest == null) return filterSearch;
filterSearch = filterSearch.Or(x => x.DisplayName.Contains(SearchRequest));
Expression<Func<GlobalSearchResultItem, bool>> filterSearchText = x => true;
filterSearch = filterSearch.And(filterSearchText);
return filterSearch;
}
}
Comments
Post a Comment