I am trying to upload a bunch of files to a SharePoint server. But I want to set the file-metadata before uploading so that it matches with SharePoint property and buckets it. Need help in setting file-metadata by powershell/FSRM FCI SharePoint property is day, month, year. The SharePoint application is not installed on my system. So i don't have any access to the cmdlets/SharePoint management console. The source can be from local system win7 sp1/ remote system win 08 R2.

Currently using :

$webclient = New-Object System.Net.WebClient 
$webClient.UseDefaultCredentials = $true
$webclient.UploadFile($destination + "/" + $file.Name, "PUT", $file.FullName)

Update from OP:

Sorry, don't have enough reputation to comment. But I don't think I explained my problem clearly.

Excel files contain a start-date and end-date column inside it. In order for my sharepoint server to group by Month and Year I need to ensure these properties are populated programmatically prior to upload.

I have achieved upload via calling powershell script on FSRM. e.g. Script1.ps1.

My approach: I defined a property 'Year' in classification properties and realised I will need a powershell classification rule. Saying if end-date > current_date then populate year(current_date) else year(end_date).Same with 'Month'. How to do this in powershell? Once this is done I will schedule both tasks one after the other. Thanks.

  • By metadata you mean the properties of the file? I doubt we can set before we upload a file in the library.
    – Asad Refai
    Feb 23, 2016 at 5:55

2 Answers 2


You can create a console application and write CSOM code like below:

using (var clientContext = new ClientContext(url))
     using (var fs = new FileStream(fileName, FileMode.Open))
         var fi = new FileInfo(fileName);
         var list = clientContext.Web.Lists.GetByTitle(listTitle);
         var fileUrl = String.Format("{0}/{1}", list.RootFolder.ServerRelativeUrl, fi.Name);

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

SaveBinaryDirect is quite a powerful function.

Here’s a quick example of how to upload a document on a SharePoint server using the SharePoint PowerShell module which uses the SharePoint Object Model.

# Set the variables 
$WebURL = “http://Siteurl/sites/stuff” 
$DocLibName = “Docs” 
$FilePath = “C:\Docs\stuff\Secret Sauce.docx” 

# Get a variable that points to the folder 
$Web = Get-SPWeb $WebURL 
$List = $Web.GetFolder($DocLibName) 
$Files = $List.Files

# Get just the name of the file from the whole path 
$FileName = $FilePath.Substring($FilePath.LastIndexOf("\")+1)

# Load the file into a variable 
$File= Get-ChildItem $FilePath

# Upload it to SharePoint 
$Files.Add($DocLibName +"/" + $FileName,$File.OpenRead(),$false) 
  • For more information see this below link. Upload a file Feb 23, 2016 at 5:36
  • 3
    This is server side code, the question is how to upload files with metadata from a machine outside the SharePoint farm (which would require CSOM code) Feb 23, 2016 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.