Articles about European Sharepoint Hosting Service
Other Related Post

Sharepoint 2013 Hosting – HostForLIFE.eu :: Sharepoint 2013 Hosting – HostForLIFE.eu ::
Jan 10th
In this blog, I am going to perform two actions –
- Identify if a page is a modern page or not.
- Migrate or copy that modern page (including its content) to another site collection or site (destination location)
I am going to accomplish these tasks by using CSOM (Client Object Model). After identifying the modern page, I will copy the modern page into another site collection (destination location) and then, will migrate all the page contents of this modern page (including web parts and other properties of source modern page) to a destination web using CSOM.
We are using a console application to achieve the above functionality using CSOM. In the below-mentioned code logic, we will get all pages from ‘Site Pages’ page library which is present in the source web and looping each page to check if that is a modern page or not.
If the page is found to be a modern page, then we are migrating that page to the destination web ‘Site Pages’ library.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
using System; using System.Net; using System.Security; using System.Text.RegularExpressions; using Microsoft.SharePoint.Client; namespace ConsoleApp1 { class Program { static void Main(string[] args) { ClientContext sourceContext = null; List sourceList = null; ListItemCollection srcItemCollection = null; ListItem sourceItem = null; string userName = string.Empty; string password = string.Empty; SecureString srcSiteSecurePassword = new SecureString(); SharePointOnlineCredentials sourceOnlineCredentials = null; try { using(sourceContext = new ClientContext("http://sourcesiteurl")) { userName = "TestUser"; password = "Password"; if (!string.IsNullOrEmpty(password)) { foreach(char c in password.ToCharArray()) srcSiteSecurePassword.AppendChar(c); } // Setting credential for the above site sourceOnlineCredentials = new SharePointOnlineCredentials(userName, srcSiteSecurePassword); sourceContext.Credentials = sourceOnlineCredentials; sourceContext.Load(sourceContext.Web); sourceContext.ExecuteQuery(); // Getting source list by Title sourceList = sourceContext.Web.Lists.GetByTitle("Site Pages"); // Getting all items from source list using caml query srcItemCollection = sourceList.GetItems(CamlQuery.CreateAllItemsQuery()); //Loading source items sourceContext.Load(srcItemCollection, IC => IC.Include(I => I.Id, I => I.DisplayName)); sourceContext.ExecuteQuery(); if (srcItemCollection != null && srcItemCollection.Count > 0) { for (int iCount = 0; iCount < srcItemCollection.Count; iCount++) { try { sourceItem = srcItemCollection[iCount]; //Checking if current page is modern page or not if (IsModernPage(sourceContext, sourceItem)) { // Migrate modern page to anothen site MigrateModernPageToAnotherWeb(sourceContext, sourceItem); } } catch (Exception ex) {} } } } } catch (Exception ex) {} } // Checking if the selected page is a modern page or not private static bool IsModernPage(ClientContext sourceContext, ListItem sourceItem) { bool isModernPage = false; try { sourceContext.Load(sourceItem, srcItm => srcItm["CanvasContent1"], srcItm => srcItm["LayoutWebpartsContent"]); sourceContext.ExecuteQuery(); // Check if modern page if (!string.IsNullOrEmpty(sourceItem["CanvasContent1"].ToString()) || !string.IsNullOrEmpty(sourceItem["LayoutWebpartsContent"].ToString())) isModernPage = true; } catch { isModernPage = false; } return isModernPage; } // Migrating the modern page from source site to destination site private static void MigrateModernPageToAnotherWeb(ClientContext sourceContext, ListItem sourceItem) { ClientContext destSiteContext = null; List destList = null; ListItem destItem = null; string userName = string.Empty; string password = string.Empty; SecureString destSiteSecurePassword = new SecureString(); SharePointOnlineCredentials destOnlineCredentials = null; string canvasContent = string.Empty; string metaInfo = string.Empty; string layoutWebpartsContent = string.Empty; try { using(destSiteContext = new ClientContext("http://destinationsiteurl")) { userName = "TestUser"; password = "Password"; if (!string.IsNullOrEmpty(password)) { foreach(char c in password.ToCharArray()) destSiteSecurePassword.AppendChar(c); } // Setting credential for the above site destOnlineCredentials = new SharePointOnlineCredentials(userName, destSiteSecurePassword); destSiteContext.Credentials = destOnlineCredentials; destSiteContext.Load(destSiteContext.Web); destSiteContext.ExecuteQuery(); // Getting destination list by Title destList = destSiteContext.Web.Lists.GetByTitle("Site Pages"); // Loading destination list destSiteContext.Load(destList, L => L.RootFolder.ServerRelativeUrl); destSiteContext.ExecuteQuery(); // Creating modern page in destination site destItem = destList.RootFolder.Files.AddTemplateFile(destList.RootFolder.ServerRelativeUrl.TrimEnd('/') + "/" + sourceItem.DisplayName + ".aspx", TemplateFileType.ClientSidePage).ListItemAllFields; destSiteContext.Load(destItem); destSiteContext.ExecuteQuery(); // Loading source item properties sourceContext.Load(sourceItem, i => i.ContentType.Id, i => i["CanvasContent1"], i => i["MetaInfo"], i => i["LayoutWebpartsContent"]); sourceContext.ExecuteQuery(); try { destItem["ContentTypeId"] = sourceItem.ContentType.Id.ToString(); canvasContent = sourceItem["CanvasContent1"].ToString(); // Replacing source Web ID with destination Web ID if (!string.IsNullOrEmpty(canvasContent) && canvasContent.Length > 0 && canvasContent.ToLower().Contains(sourceContext.Web.Id.ToString().ToLower())) canvasContent = Regex.Replace(canvasContent, sourceContext.Web.Id.ToString(), destSiteContext.Web.Id.ToString(), RegexOptions.IgnoreCase); } catch (Exception ex) {} try { metaInfo = sourceItem["MetaInfo"].ToString(); // Replacing source Web ID with destination Web ID if (!string.IsNullOrEmpty(metaInfo) && metaInfo.Length > 0 && metaInfo.ToLower().Contains(sourceContext.Web.Id.ToString().ToLower())) metaInfo = Regex.Replace(metaInfo, sourceContext.Web.Id.ToString(), destSiteContext.Web.Id.ToString(), RegexOptions.IgnoreCase); } catch (Exception ex) {} try { layoutWebpartsContent = sourceItem["LayoutWebpartsContent"].ToString(); // Replacing source Web ID with destination Web ID if (!string.IsNullOrEmpty(layoutWebpartsContent) && layoutWebpartsContent.Length > 0 && layoutWebpartsContent.ToLower().Contains(sourceContext.Web.Id.ToString().ToLower())) layoutWebpartsContent = Regex.Replace(layoutWebpartsContent, sourceContext.Web.Id.ToString(), destSiteContext.Web.Id.ToString(), RegexOptions.IgnoreCase); } catch (Exception ex) {} // Setting source page canvas content to destination page if (!string.IsNullOrEmpty(canvasContent) && canvasContent.Length > 0) destItem["CanvasContent1"] = canvasContent; // Setting source page metaInfo content to destination page if (!string.IsNullOrEmpty(metaInfo) && metaInfo.Length > 0) destItem["MetaInfo"] = metaInfo; // Setting source page layout webparts content to destination page if (!string.IsNullOrEmpty(layoutWebpartsContent) && layoutWebpartsContent.Length > 0) destItem["LayoutWebpartsContent"] = layoutWebpartsContent; // Updating the destination page destItem.Update(); destSiteContext.ExecuteQuery(); } } catch (Exception ex) {} } } } |
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options

SharePoint 2013 Hosting – HostForLIFE.eu :: Console Application To Fetch SharePoint List Data Using REST API With CAML Query In C# Managed Code
Apr 12th
SharePoint 2013 has many restful APIs to fetch the data from lists. However, sometimes, we need to use a CAML query to filter out the data. SharePoint Rest API has an option to pass a CAML query as data to an API call. The below steps will help you to call a Rest API with CAML query filtering. In addition, this article will help you to understand how to call REST API POST methods in console applications using C# managed code. The below example calls a REST API to retrieve the data from Department SharePoint list. Department list has a Title column, which refers to the department name. CAML query will be used to filter the Department list data by Title (Department name).
REST endpoint /_api/web/lists/getbytitle(‘Department’)/GetItems CAML Query Structure CAML query structure should be strictly followed as below: <View><Query> <CAML_Query> </Query></View> Assembly References
- Net: To make a request to a Uniform Resource Identifier (URI).
- Web.Script.Serialization: For serialization and deserialization functionality
- IO: For reading and writing streams.
Request Header for POST Request The API endpoint is of type POST. Hence, the REST header should be same as other post requests,
- oWebRequest.Accept = “application/json;odata=verbose”;
- oWebRequest.ContentType = “application/json;odata=verbose”;
- oWebRequest.Headers.Add(“X-RequestDigest”, GetFormDigest());
- oWebRequest.ContentLength = stringData.Length;
Steps Please follow the below steps to create a console application:
- Open Visual Studio.
- Select Console Application template and provide a suitable name.
- Add required assemblies.
- Add the below code in Program.cs file.
- Run the code.
Code Explanation
- The complete data to be passed in the request will be:
- “{‘query’ : {‘__metadata’: { ‘type’: ‘SP.CamlQuery’ }, ‘ViewXml’:'<View><Query><Where><Eq><FieldRef Name =\”Title\”/><Value Type=\”Text\”>HR</Value></Eq></Where></Query></View>’}}”;
- Form Digest need to be passed while calling post method. GetFormDigest() returns the required request digest.
Summary In this article, we have explored how to call SharePoint REST API with CAML query in C# console application. The CAML query can also be passed through the URL itself. However, this makes the API URL complicated and sometimes, restricts the length of the URL. The same code can be used in implementing custom APIs as well.

SharePoint 2013 Hosting – HostForLIFE.eu :: How to Copy Item Attachments To SharePoint Library Using PnP PowerShell?
Mar 1st
In this blog, we are going to learn how to copy the attachments from a single list item to SharePoint library using PnP PowerShell. The following snippet helps, you to get the attachments from a list item and uploads to the shared Documents library in a current context site.
1 2 3 4 5 6 7 |
$cred = Get-Credential Connect-PnPOnline -Url https://ktskumartenant.sharepoint.com/sites/dev -Credential $cred $listitem = Get-PnPListItem -List Employee -Id 2 $attachments = ForEach-Object{Get-PnPProperty -ClientObject $listitem -Property "AttachmentFiles"} $attachments | ForEach-Object { Copy-PnPFile -SourceUrl $_.ServerRelativeUrl –TargetUrl “Shared Documents/$($_.FileName)” |
After running the powershell command, it asks us to confirm the sourceurl and target url. If the file already exists in the targeturl, we have to add -OverwriteIfAlreadyExists $true to avoid the file already exists error.
Below is the example copies the two attachments from the single list item to the folder within a SharePoint library.
SharePoint 2013 Hosting – HostForLIFE.eu :: How to Create Result Source In SharePoint 2013 Search Using PowerShell?
Jul 27th
This blog post describes how to create a search result source using PowerShell in SharePoint 2013. I have a requirement to add additional search rules which will be used with the keywords entered by the user in the search box, then you will need to create custom search result source. The query will be,
1 |
{searchTerms} Author={User.Name} FileType=pdf FileType=docx |
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
Add-PSSnapin Microsoft.SharePoint.PowerShell $SearchServiceApp = Get-SPEnterpriseSearchServiceApplication $fedmanager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($SearchServiceApp) $searchOwner = Get-SPEnterpriseSearchOwner -Level Ssa $resultSourceName = "Search" $urlTemplate = "http://yoursharepointsitename/search?q={searchTerms}&format=rss&Market=en-Us" $qT = "{searchTerms}" $ResultSource = $fedmanager.GetSourceByName($resultSourceName, $searchOwner) if(!$ResultSource){ Write-Host "Result source does not exist. Creating." $ResultSource = $fedmanager.CreateSource($searchOwner) } else { Write-Host "Using existing result source." } $ResultSource.Name =$resultSourceName $ResultSource.ProviderId = $fedmanager.ListProviders()['OpenSearch Provider'].Id $ResultSource.ConnectionUrlTemplate = $urlTemplate $ResultSource.CreateQueryTransform($queryProperties,$qT) $ResultSource.Commit() |

SharePoint 2013 Hosting – HostForLIFE.eu :: How to Arrange Choice Field’s CheckBoxes On SharePoint Forms?
Apr 11th
If a choice field in SharePoint is set to Check Box and the choice field values are in a large number, then the field values are arranged vertically. So, I have made an effort to arrange the checkboxes (choice values) horizontally. I am sharing this with a motif to save your time.
In the below code, I have put everything into a function where I first find out the total number of choice values by picking the selector and crawling through the hierarchy of HTML tags to get “.ms-RadioText”.
And then, get the total by using length.
e.g. var len = $(“#trainTopic table tbody tr td .ms-RadioText”).length;
Then, decide on how many values you need in one row. The loops used in code are as shown below.
e.g. Outer Loop: for (i = 0; i < len; i = i + 4)
Inner Loop: for (j = i + 1; j <= i + 3; j++)
The numbers 4 and 3 in outer and inner loops respectively state that 4 columns will be created or we can say 4 choice values will be put in each row created.
You, then, loop through the full length of choice values and the iterations of this loop will take a jump of 4 counts as the number of columns I need is just 4.
And in every iteration of the outer loop, I find the row in which the 4th + 1 choice value resides in by picking the choice value in the list and find the <tr></tr> in which it stands.
The inner loop arranges the next 3 choice values i.e. the <td></td> in which it resides in the same row as the first choice value.
And, here we go.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
function ArrangeCheckBoxes() { var len = $("#choiceField table tbody tr td .ms-RadioText").length; temp = len - 1; count = 0; var startingElement; for (i = 0; i < len; i = i + 4) { if (count == temp) break; startingElement = $("#choiceField table tbody tr td .ms-RadioText:eq(" + i + ")").closest('tr') count++; for (j = i + 1; j <= i + 3; j++) { if (count == temp) break; $("#choiceField table tbody tr td .ms-RadioText:eq(" + (j) + ")").closest('td').appendTo(startingElement); count++; } } } |
HostForLIFE.eu Proudly Launches Umbraco 7.5.7 Hosting
Jan 27th
HostForLIFE.eu, a leading Windows web hosting provider with innovative technology solutions and a dedicated professional services team, today announced the support for Umbraco 7.5.7 hosting plan due to high demand of Umbraco users in Europe. The company has managed to build a strong client base in a very short period of time. It is known for offering ultra-fast, fully-managed and secured services in the competitive market.
HostForLIFE.eu hosts its servers in top class data centers that is located in Amsterdam, (NL), London, (UK), Washington, D.C. (US), Paris, (France), Frankfurt, (Germany), Chennai, (India), Milan, (Italy), Toronto, (Canada) and São Paulo, (Brazil) to guarantee 99.9% network uptime. All data centers feature redundancies in network connectivity, power, HVAC, security and fire suppression. All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee. HostForLIFE Umbraco hosting plan starts from just as low as €3.49/month only and this plan has supported ASP.NET Core 1.1, ASP.NET MVC 5/6 and SQL Server 2012/2014/2016.
Umbraco is a fully-featured open source content management system with the flexibility to run anything from small campaign or brochure sites right through to complex applications for Fortune 500’s and some of the largest media sites in the world. Umbraco is strongly supported by both an active and welcoming community of users around the world, and backed up by a rock-solid commercial organization providing professional support and tools. Umbraco can be used in its free, open-source format with the additional option of professional tools and support if required.
Umbraco release that exemplifies our mission to continue to make Umbraco a bit simpler every day. The other change is that there’s now a “ValidatingRequest” event you can hook into. This event allows you to “massage” any of the requests to ImageProcessor to your own liking. So if you’d want to never allow any requests to change BackgroundColor, you can cancel that from the event. Similarly if you have a predefined set of crops that are allowed, you could make sure that no other crop sizes will be processed than those ones you have defined ahead of time.
Further information and the full range of features Umbraco 7.5.7 Hosting can be viewed here: http://hostforlife.eu/European-Umbraco-757-Hosting