WebHosting

Wednesday, November 16, 2011

Upload document from Local Machine to SharePoint Library using WebService


Parameters,

SourceUrl:
String that contains the absolute source URL of the document to be copied.
DestinationUrls:
An array of Strings that contain one or more absolute URLs specifying the destination location or locations of the copied document.
Fields:
An array of FieldInformation objects that define and optionally assign values to one or more fields associated with the copied document.
Stream:
An array of Bytes that contain the document to copy using base-64 encoding.
Results:
An array of CopyResult objects, passed as an out parameter.
Return Value:
UInt32 that returns 0 to indicate that the operation has completed. (There is also an out parameter containing an array of CopyResult objects.)
Below i’m providing a code for uploading a document to SharePoint Library,


//Copy WebService Settings
string webUrl = “http://localhost:1000″;
WSCopy.Copy copyService = new WSCopy.Copy();
copyService.Url = webUrl+”/_vti_bin/copy.asmx”;
copyService.Credentials = System.Net.CredentialCache.DefaultCredentials;
//Declare and initiates the Copy WebService members for uploading
string sourceUrl = “C:\\Sample.doc”;
string[] destinationUrl = { “http://localhost:1000/Shared Documents/Sample.doc” };
WSCopy.CopyResult cResult1 = new WSCopy.CopyResult();
WSCopy.CopyResult cResult2 = new WSCopy.CopyResult();
WSCopy.CopyResult[] cResultArray = { cResult1, cResult2 };
WSCopy.FieldInformation fFiledInfo = new WSCopy.FieldInformation();
fFiledInfo.DisplayName = “Description”;
fFiledInfo.Type = WSCopy.FieldType.Text;
fFiledInfo.Value = “Sample Description”;
WSCopy.FieldInformation[] fFiledInfoArray = { fFiledInfo };
//Reading the document contents in to stream
FileStream strm = new FileStream(sourceUrl, FileMode.Open, FileAccess.Read);
byte[] fileContents = new Byte[strm.Length];
byte[] r = new Byte[strm.Length];
int ia = strm.Read(fileContents, 0, Convert.ToInt32(strm.Length));
strm.Close();
//Copy the document from SourceUrl to destinationUrl with metadatas
uint copyresult = copyService.CopyIntoItems(sourceUrl, destinationUrl, fFiledInfoArray, fileContents, out cResultArray);
* Where WSCopy is the WebReference Name and the document is uploaded successfully, copyresult returns 0.

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

How to Enable and Configure Remote Desktop (RDP) on Ubuntu 24.04.4 LTS

Remote Desktop Protocol (RDP) support in Ubuntu has become considerably easier with the GNOME Remote Desktop stack included in modern Ubuntu...