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 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;