30 October, 2013
0 Comments
1 category
If you want to create a folder in a document library, by using WebClient in C#, you can use the following code:
namespace Research { using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Net; [TestClass] public class RliResearch { [TestMethod] public void CreateSharePointFolderInDocumentLibrary() { string folderToCreateUri = "https://1.1.1.1/sites/mysite/Shared%20Documents/FolderIWantToCreate"; using (var client = new WebClient()) { client.Credentials = CredentialCache.DefaultCredentials; client.UploadString(folderToCreateUri, "MKCOL", ""); } } } }
Note: The folder you want to create the folder in, must exist. In other words: create subfolder hierarchy one at a time.
To create the folder hierarchy:
Shared Documents
SubLevel1
SubLevel2
namespace Research { using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Net; [TestClass] public class RliResearch { [TestMethod] public void CreateSharePointFolderInDocumentLibrary() { string sublevel1 = "https://1.1.1.1/sites/mysite/Shared%20Documents/SubLevel1"; using (var client = new WebClient()) { client.Credentials = CredentialCache.DefaultCredentials; client.UploadString(sublevel1, "MKCOL", ""); } string sublevel2 = "https://1.1.1.1/sites/mysite/Shared%20Documents/SubLevel1/SubLevel2"; using (var client = new WebClient()) { client.Credentials = CredentialCache.DefaultCredentials; client.UploadString(sublevel2, "MKCOL", ""); } } } }
Tags: C#SharePoint
Category: Uncategorized
how to put a validation for this “if the folder is exist then ignore, if not exist then create?”