Don't wanna be here? Send us removal request.
Link
#sharepoint#PowerApps#MSFlow#PowerApps with Microsoft Flow#Send email using MS Flow#Send email using Power Apps
0 notes
Link
Basically, when we are trying to update a SharePoint ListItem/Document then the item/file version is increased according to the list versioning. In the Server side object model, we can update a ListItem without increasing its file version by setting ‘SystemUpdate’ as false. But in CSOM ‘SystemUpdate’ property is not supported.
0 notes
Link
0 notes
Link
#import term sets using powershell script#How to Import Managed Metadata into SharePoint#How to Import Managed Metadata presents in csv file into SharePoint#import managed metadata using Central Administration#Import term sets into SharePoint
0 notes
Text
How to get all SharePoint List item versions using 'Client Side Object' model both for Custom list and Document Library?
Basically, in CSOM, there is no direct property to get the item versions from a List Item. But by using "Lists Web Service"(/_vti_bin/Lists.asmx) we can get all versions and properties information for each item inside Custom List or Document Library.
To get the above-required functionality, first of all, we have added the "Lists Web Service" in the required project.
In this blog, I am going share all codes how we can get all List Items version by using "Lists Web Service". We all know how to add a service inside a project.
I am using a simple Console application to iterate all item versions information. Please follow the below code...
using System; using System.Net; using System.Xml;
using Microsoft.SharePoint.Client;
namespace ConsoleApp1 { class Program { static void Main(string[] args) { ClientContext context = null; List list = null; ListItemCollection itemCollection = null; ListItem item = null;
string userName = string.Empty; string password = string.Empty; string dateHistory = string.Empty; string commentHistory = string.Empty; string editor = string.Empty; string loginName = string.Empty;
try { using (context = new ClientContext("http://SourceWebUrl")) { userName = "UserName"; password = "PassWord";
// Setting credential for the above site context.Credentials = new NetworkCredential(userName, password); context.Load(context.Web); context.ExecuteQuery();
// Getting list by Title list = context.Web.Lists.GetByTitle("Custom List"); context.Load(list, L => L.Id);
// Getting all items from selected list using caml query itemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery());
//Loading selected list items context.Load(itemCollection, IC => IC.Include(I => I.Id, I => I.DisplayName)); context.ExecuteQuery();
if (itemCollection != null && itemCollection.Count > 0) { for (int iCount = 0; iCount < itemCollection.Count; iCount++) { try { item = itemCollection[iCount];
ListService.Lists listService = new ListService.Lists(); listService.Url = context.Url + "/_vti_bin/Lists.asmx"; listService.Credentials = context.Credentials;
//Getting all item versions from custon list item using List Web Service XmlNode nodeVersions = listService.GetVersionCollection(list.Id.ToString(), item.Id.ToString(), "_UIVersionString");
//looping all versions and getting 'Modified' and 'Editor' property of each version foreach (XmlNode xNode in nodeVersions) { try { dateHistory = xNode.Attributes["Modified"].Value; dateHistory = FormatDateFromSP(dateHistory); commentHistory = xNode.Attributes["_UIVersionString"].Value; loginName = xNode.Attributes["Editor"].Value; } catch { } } } catch (Exception ex) { } } } } } catch (Exception ex) { } }
private static string FormatDateFromSP(string dateHistory) { string result;
result = dateHistory.Replace("T", " "); result = result.Replace("Z", "");
return result; } } }
This solution is brought to you by our SharePoint professionals.
Softree Consulting employs SharePoint consultants; we are a technology services provider with the aim to help companies achieve exceptional performance through SharePoint. Our dedicated team of SharePoint consultants has the right bent of mind to understand and execute customer requirements.
Be it SPFx or SharePoint add-in developments, SharePoint 2019 developments, web part developments, migrating from SharePoint 2010/2013 to SharePoint 2013/2016/Office 365, Office 365, SharePoint hosted apps development or something else in SharePoint, we strive to deliver the best
#How to get List Item Versions using CSOM#All SharePoint List Item Versions#Client Side Object Model#Custom List And Document Librar
0 notes
Text
Identify The Modern Pages And Copy Them To Another Site Collection
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. Please have a look at the below code. The code is self-explanatory because of the comments.
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) {}
}
}
}
Destination Page Library Before Migration: –
Destination Page Library after Migration:-
After executing the above code behind, you can find the newly created modern page in the destination web ‘Site Pages’ library with the same page contents and “web parts” as they were in the source page.
This solution is brought to you by our SharePoint professionals.
Softree Consulting employs SharePoint consultants; we are a technology services provider with the aim to help companies achieve exceptional performance through SharePoint. Our dedicated team of SharePoint consultants has the right bent of mind to understand and execute customer requirements.
Be it SPFx or SharePoint add-in developments, SharePoint 2019 developments, web part developments, migrating from SharePoint 2010/2013 to SharePoint 2013/2016/Office 365, Office 365, SharePoint hosted apps development or something else in SharePoint, we strive to deliver the best
0 notes