Upload files to a folder in WSS

  • Thread starter Thread starter Kannan
  • Start date Start date
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;
 
I don't program with the WebClient object myself and am not personally aware
of any incompatibilities with WSS, you are using the POST method so code
access shouldn't be making a fuss. Have you thought about writing a full
object model web service - it would give you access into the file's metadata
as well as jsut dumping the file.
 
Back
Top