Code Samples, Simple Translation using CSOM, REST, and Machine Translation Services

Machine Translation Services is a powerful Shared Service Application in SharePoint Server 2013 that provides automation synchronous and asynchronous translation of documents, folders, and sites.  The code samples in this post provide simple examples of synchronous document translation using the Client Side Object Model in managed (C#) applications and Windows PowerShell in addition to accessing Machine Translation Services via REST.


The Client Side Object Model (CSOM) provides a rich alternative to earlier Web Services in providing an object-oriented system for interoperating with SharePoint data from a remote (client) machine.

The foundation of CSOM interop is the client context object which represents the current request context.  In the provided samples, it is represented in the C# example as:

new ClientContext(site)

or in the Windows PowerShell sample as:

New-Object Microsoft.SharePoint.Client.ClientContext($url) where the $url in this example is a parameter passed to the script.

Through this context you can obtain access to client objects to include site collections and their subordinates as represented in the above examples.

For example, in the sample scripts (download link below), the top-level site collection represents the new client context which is passed to the SyncTranslator class of the TranslationServices namespace as the Context property.

$context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
$context.Credentials = $credentials

$job = New-Object Microsoft.Office.Client.TranslationServices.SyncTranslator($context, $language)


REST or Representational State Transfer in the context of SharePoint 2013 development opens it to standard Web languages and technologies.  Technologies such as CSOM (as shown above) have been available to SharePoint over several releases; however, such APIs are limited to .NET applications and languages.  REST; however, enables accessing SharePoint capabilities and entities with standard Web languages such as JavaScript and preprocessor hypertext (PHP) in addition to any technology stack that supports REST.   One of the predominant benefits of REST is that it allows for limiting the footprint of Web applications, as such, reduces the barrier to entry to accessing cloud services and deploying applications whose target is such.

In SharePoint the REST service is implemented in client.svc contained within _vti_bin; however, through substitution _api is used and establishes the base Url for each endpoint.

The service Url of specific endpoints is appended to the base Url, in the sample code:

$request = [System.Net.WebRequest]::Create($url +"/_api/TranslationJob.EnumerateSupportedLanguages")

These samples are intended to illustrate how Windows PowerShell can be used to access cloud services through CSOM and REST.

Download the samples here:

CSOM (Windows PowerShell and C# Samples)

REST (Windows PowerShell Samples)

File and Folder Considerations with OneDrive for Business [UPDATED 12/10/2014]

Updated 8/12/2014 – Removed & as an illegal character.  & character is now supported with OneDrive for Business sync client and Web UX.

Updated 8/22/2014 – Updated to include prohibited types per

Updated 8/23/2014 – Updated to include optional UI-based scanning (FileCheckerUI.exe).

Updated 8/31/2014 – Updated FileChecker.exe (integrated desktop and command line application).

Updated 12/10/2014  Updated to remove prohibited characters {, }, [, ], ~, and ..  Updated FileChecker.exe

When considering a migration to OneDrive for Business you should be aware of the specific File and Folder considerations and restrictions.  While some considerations exist that are explicit to OneDrive for Business and SharePoint; others are derivatives of the underlying client and/or server file system.  For example, on Microsoft Windows the following characters cannot be used in paths or files:






The above represents an array returned by the Path.GetInvalidFileNameChars and Path.GetInvalidPathChars methods respectively.  These methods; however, do not return a complete set of characters invalid in file and path names as they can differ depending on the underlying file system.  On Windows-based desktop platforms, invalid path characters might include ASCII/Unicode characters 1 through 31, as well as quote (“), less than (<), greater than (>), pipe (|), backspace (b), null () and tab (t) in addition to those in the example above.

File and Folders preceded with (_).

Files and Folders whose name is preceded with the (_) are considered ‘hidden’.  This limitation is derived from the Win32FileAttributes in the WebDAV protocol.  In scenarios where a File and/or Folder are preceded with (_), such as _Documents or _document.docx, in both cases the File and/or Folder will be visible in the OneDrive for Business Sync Client as well as the Web UI; however, when using Explorer View in the Web UI, Files and Folders preceded with (_) will not be visible.  Explorer View in OneDrive for Business uses the WebDAV protocol.  WebDAV refers to Web Distributed Authoring and Versioning, an extension of the HTTP protocol that is used to enable management of documents stored on WWW servers.  The scenario herein is based on limitations implied in FrontPage 2000 (see also

In OneDrive for Business Explorer View can be instantiated by selected the Open with Explorer option in the Ribbon.


When you use Open with Explorer, it opens Windows Explorer on your computer, but it displays the folder structure on the server computer that underlies the site.  You can manipulate the files in the folder, such as copying, renaming, deleting, etc.

Customers who have deployed OneDrive for Business on-premises can nullify the Win32FileAttributes using Windows PowerShell or C# as illustrated in the samples below:

Windows PowerShell

For IT Professionals you can use Windows PowerShell to remove the vti_winfileattribs folder metadata as shown in the example below.

$Folder = (Get-SPWeb[“<DocLib_Name>”].SubFolders[“<_Folder_Name>”]



Developers can use the SPFolder.Properties property to enumerate the hash table that contains the metadata for folders and implement the DeleteProperty method to deletes the element with the vti_winfileattribs key from the metadata for the folder.  See also for an explanation and examples of using the SPFolder.DeleteProperty method.

WebDAV Resources

WebDAV API Functions []

[MS-WDV]: Web Distributed Authoring and Versioning (WebDAV) Protocol: Client Extensions []

[MS-WDVSE]: Web Distributed Authoring and Versioning (WebDAV) Protocol: Server Extensions []

Files and Folders preceded or followed with (.).

A number of restrictions with File and Folder naming convention are derivative of the the File System, developers who use the Windows APIs for file and device I/O in many cases, understand the various rules, conventions, and limitations of names for files and directories.

Files and Folders whose name is preceded or followed with the (.) character cannot be stored or synchronized with the OneDrive for Business.  All file systems follow the same general naming conventions for an individual file: a base file name and an optional extension, separated by a period.   The assumption in this case is (.) separates the base file name from the extension in the name of a directory or file.

Restricted Characters in File and Folder Names

Beyond those limitations documented above, users can create Files and Folders using any character including Unicode characters and characters in the extended character set (128–255), except for the following reserved characters:

  • < (less than)
  • > (greater than)
  • : (colon)
  • ” (double quote)
  • / (forward slash)
  • (backslash)
  • | (vertical bar or pipe)
  • ? (question mark)
  • * (asterisk)

These limitations are applicable to Microsoft Windows.

In addition you cannot use the:

  • ~ (Tilde)
  • # (Number Sign)
  • % (Percent)
  • [ ] (Braces)
  • { } (Angle Brackets)
  • ? (Question Mark)
  • You cannot use the period character consecutively in the middle of a folder name.  In the Windows File System, two consecutive periods (..) are used as a directory component in a path to represent the parent of the current directory, for example “..temp.txt”.

These limitations are applicable to OneDrive for Business and SharePoint 2013.  For additional information see also

Other Considerations

SharePoint 2013 and OneDrive for Business do not provide support for POSIX semantics, that is a Folder “Foo” and “foo” are considered the same, as opposed to differing paths.

Validating File and Folder Names

Developers can validate File and Folder names using a number of methods.  The sample code at uses Regular Expressions to deterministically identify illegal characters in a File name.


FileChecker.exe -d C:Temp


Source Directory