SharePoint: Upload file using Web Service

We need to create a utility that runs on client machine and upload file on pre-defined schedule or as per requirement. The details of code to upload file is as under:

We added Copy web service (http://[ServerURL]/_vti_bin/copy.asmx) in our project assigning name “SPCopyService”.

using WSUploadFile.SPCopyService;

using System.IO; 

namespace WSUploadFile

class Program


static void Main(string[] args)


Copy CopyWS = new Copy();

CopyWS.Credentials = new System.Net.NetworkCredential(“login”, “password”, “domain”);

CopyWS.Url = http://ServerURL/prototype/_vti_bin/copy.asmx”;

String filePath = @”\\NetworkFolderPath\ABC.xls”;

String[] destURL = { http://ServerName/SiteName/Shared Documents/ABC.xls”};

FileStream fstrm = new

byte[] contents = new



FieldInformation fileFieldInfo = new

fileFieldInfo.DisplayName = “ABC”;

fileFieldInfo.Value = “ABC”;

fileFieldInfo.InternalName = “ABC”;

fileFieldInfo.Type = SPCopyService.FieldType.Text;

FieldInformation[] fileFieldInfoArray = { fileFieldInfo };

CopyResult result1 = new CopyResult();

CopyResult result2 = new CopyResult();

CopyResult[] resultArray = { result1, result2 };

uint resultCopy = CopyWS.CopyIntoItems(filePath, destURL, fileFieldInfoArray, contents, out resultArray);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: