C# Remove Method

The Remove method is a nice alternative to substring method
For example,

string strStringToTruncate = “This is a beautiful house”;

string strTruncatedString = strStringToTruncate.Remove(5,10);
strTruncatedString = strStringToTruncate.Remove(5);
strTruncatedString = strStringToTruncate.Remove(0,5);

The result
“This iful house”
“is a beautiful house”

More information can be found

The method removes a number of characters based on a start index.

Programmatically create InfoPath form using CSOM SharePoint 2010

The blog posts below describe how to create InfoPath form instance using server side code and the class InfopathFormGrocker

To use CSOM the application has to be modified as follows

1. Add the following assemblies

2. Get the InfoPath file from the content type

var clientContext = new ClientContext(siteUrl);
var list = clientContext.Web.Lists.GetByTitle(listName);

//get list level content type using ContentTypeExtensions
var listContentType = clientContext.Web.Lists.GetByTitle(listName).ContentTypes.GetByName(listContentTypeName);
var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, listContentType.DocumentTemplateUrl);

In the above example ContentTypeExtensions has been used to be able to get content type by name. More information can be found at

3. Using InfopathFormGrocker, the manifest.xsf and template.xml need to be extracted after converting the fileInfo object into memorystream

// get the Manifest xsf file
var memoryManifest = new MemoryStream();

byte[] bufferManifest = new byte[1024 * 64];
int nreadManifest = 0;
while ((nreadManifest = fileInfo.Stream.Read(bufferManifest, 0, bufferManifest.Length)) > 0)
memoryManifest.Write(bufferManifest, 0, nreadManifest);

xsnForm.ExtractComponent(memoryManifest, "manifest.xsf");
XmlDocument formManifest = xsnForm.ComponentContent;

//memory is closed explaining why it is reinitialised
fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, listContentType.DocumentTemplateUrl);

// get the template Xml file

var memoryTemplate = new MemoryStream();

byte[] buffer = new byte[1024 * 64];
int nread = 0;
while ((nread = fileInfo.Stream.Read(buffer, 0, buffer.Length)) > 0)
memoryTemplate.Write(buffer, 0, nread);
xsnForm.ExtractComponent(memoryTemplate, "template.xml");
XmlDocument xsnFormTemplate = xsnForm.ComponentContent;

// get form metadata values
XmlNamespaceManager NamespaceManager = CreateNamespaceManager(formManifest);
string Name = formManifest.DocumentElement.GetAttribute("name", "");
string SolutionVersion = formManifest.DocumentElement.GetAttribute("solutionVersion", "");
string ProductVersion = formManifest.DocumentElement.GetAttribute("productVersion", "");

string HRef = listContentType.DocumentTemplateUrl;

XmlDocument formXML = CreateFormInstanceDocument(xsnFormTemplate.OuterXml, Name, SolutionVersion, ProductVersion, HRef);
//Manipulate the XMLDocument , e.g. update field properties

4. Use CSOM to upload the InfoPath to the library after converting the XmlDocument into MemoryStream

var formBytes = Encoding.UTF8.GetBytes(formXML.OuterXml);

MemoryStream xmlStream = new MemoryStream(formBytes);


var fileUrl = String.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, string.Format("Test creating InfoPath{0}.xml", DateTime.Now.ToString("yyyyMMddHHmmss")));

Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, fileUrl, xmlStream, true);

The code has been tested against SharePoint 2010. Might require some amendments to make it work for other versions of SharePoint

Updating Resources Custom Field values using CSOM, Project Online, #Project Server 2013

Project Online applications need to be written using CSOM or OData rather the PSI which will be deprecated soon.

The CSOM – Client-side object model implements common server functionality.

If you are not familiar with development in Project Server 2013 refer to the links below to learn about CSOM, OData, JSOM.

ProjectData – Project 2013 OData service reference

Client-side object model (CSOM) for Project 2013

What the CSOM does and does not do

The solution has been developed as a console app using Visual Studio 2015 allowing to specify resource name, custom resource field name , field value

The code from the console app

1. The projectContext has to be initialised using the url. If the user running the app does not have permissions to the PWA site, then user name and password need to be specified by adding the code

ProjContext.Credentials = new SharePointOnlineCredentials credentails = new SharePointOnlineCredentials(username, password);

2. Find the guid of the resource you want to update
and set it against variable resUID

3. The code find the resource based on resUID provided, the resource entity id and internal name of the resource custom field

4. The value of the custom field is updated by the following line

entRes2Edit[customfield.First().InternalName] = “3456”;
If an out of the box field is updated , e.g. CanLevel. The property can be accessed simply as follows
// Toggle the CanLevel property.
entRes2Edit.CanLevel = !entRes2Edit.CanLevel;

To commit the change , use the following lines

// Save the change.

class Program
private const string pwaPath = "https://radev/PWA/"; // Change the path for Project Web App.

// Set the Project Server client context.
private static ProjectContext projContext;

// For applications that access both the Project Server CSOM and the SharePoint CSOM, you could
// use the ProjectServer object. Those statements are commented out in this application.
// However, it is not necessary to instantiate a ProjectServer object, because the the
// ProjectContext object inherits from ClientContext in SharePoint.

static void Main(string[] args)
projContext = new ProjectContext(pwaPath);
//GUID for reshmee auckloo
Guid resUID = new Guid("02C5EE34-5CE8-E411-80C1-00155D640C06");
string customFieldName = "Staff Number";
string customFieldValue = "000000";
// Get the list of published resources and custom fields in Project Web App.


int numResInCollection = projContext.EnterpriseResources.Count();
var usrs = projContext.Web.SiteUsers;

if (numResInCollection > 0)

var entRes2Edit = projContext.EnterpriseResources.GetByGuid(resUID);

var userCustomFields = entRes2Edit.CustomFields;

Guid ResourceEntityUID = projContext.EntityTypes.ResourceEntity.ID;

var customfield = projContext.CustomFields.Where(x => x.Name == customFieldName);

entRes2Edit[customfield.First().InternalName] = "3456";

Console.WriteLine("\nEditing resource : GUID : Can Level");
Console.WriteLine("\n{0} : {1} : {2}", entRes2Edit.Name, entRes2Edit.Id.ToString(),

// Toggle the CanLevel property.
entRes2Edit.CanLevel = !entRes2Edit.CanLevel;

// The entRes2Edit object is in the EnterpriseResources collection.

// Save the change.

// Check that the change was made.

entRes2Edit = projContext.EnterpriseResources.GetByGuid(resUID);

Console.WriteLine("\n\nChanged resource : GUID : Can Level");
Console.WriteLine("\n{0} : {1} : {2}", entRes2Edit.Name, entRes2Edit.Id.ToString(),

Console.Write("\nPress any key to exit: ");



The solution can be downloaded from Github link

Exchange ActiveSync

Exchange ActiveSync devices can be configures to allow users to work in remote locations with high-latency or low-bandwidth networks. It allows users to access and reply to email messages and access calendars even when they are offline.

Below is a link to Exchange ActiveSync