views:

559

answers:

4

I have this webdav code thats creating folders in SharePoint:

HttpWebRequest request = (System.Net.HttpWebRequest)HttpWebRequest.Create(folderAddress);
                request.Credentials = wsLists.Credentials; // CredentialCache.DefaultCredentials;
                request.Method = "MKCOL";
                response = (System.Net.HttpWebResponse)request.GetResponse();
                response.Close();

How can I change the code now to upload a file now to this newly created folder. I think this is a generic webdav question, thanks

A: 

Take a look at Fast Uploading of Multiple Folder/Files with WebDAV and also check About Uploading with WebDAV To Transfer a Folder

Nathan Campos
Thanks but I would prefer to do it with HttpWebRequest, this way I don't have to admin the mapped drive.
JL
Ok! ;).........
Nathan Campos
+1  A: 

You should be able to do this with WebClient.UploadFile

see also this question for using HttpRequest: webclient-upload-file-error

or google search for WebClient.UploadFile webdav

csharptest.net
A: 

Thanks for your reply it was really helpful

JM
A: 

As soon as SharePoint usually requires authentication (often NTLM or Kerberos), I would suggest using a library designed to work with SharePoint and WebDAV, such as IT Hit WebDAV Client Libarary for .Net. Here is how to upload a file with it:

WebDavSession session = new WebDavSession(license);
session.Credentials = new NetworkCredential("User1", "pwd");
IFolder folder = session.OpenFolder(new Uri("http://server:8080/Sales"));
IResource resource = folder.CreateResource("products.xlsx");
resource.Upload("C:\\products.xlsx");

http://www.webdavsystem.com/client/programming/upload/uploading_files