Archive for September, 2009

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 Comment