Upload files to a folder in WSS

K

Kannan

Hello,
I was trying to upload a local file on a client machine to a
sharepoint folder using the WebClient object. This method is present
in a client side DLL. I need to upload the document using NTLM
authentication.

The method does not report any errors but the document does not appear
in the folder.

Here are the the two code snippets that I am working on and tested

Any help would be very appreciated.

Thanks
Kannan

/*********** Using UploadData ********************/
string uploadUrl = "http://sharepoint/sites/projectserver_102/Shared
Documents/Forms/AllItems.aspx";

//string uploadUrl = "http://sharepoint/sites/projectserver_102/Shared
Documents/";

string filePath = "C:\\Documents and Settings\\pv\\My
Documents\\test.txt";

FileInfo fiUploadFile = new FileInfo(filePath);
WebClient wcUploadAgent = new WebClient();
wcUploadAgent.Credentials = CredentialCache.DefaultCredentials;
FileStream fs = null;
fs = fiUploadFile.OpenRead();
Byte[] bUploadData = new Byte[fiUploadFile.Length];
fs.Read(bUploadData,0,bUploadData.Length);
string sResponse1 = System.Text.Encoding.ASCII.GetString(bUploadData);
Byte[] arrayBytes = wcUploadAgent.UploadData(uploadUrl,"POST",bUploadData);
string sResponse = System.Text.Encoding.ASCII.GetString(arrayBytes);


/***************** Using UploadFile ************************/
WebClient wcUploadAgent = new WebClient();
wcUploadAgent.Credentials = CredentialCache.DefaultCredentials;
Byte[] responseArray = wcUploadAgent.UploadFile(uploadUrl, "POST",
filePath);
string sResponse = System.Text.Encoding.ASCII.GetString(responseArray);
string returnValue = sResponse;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top