Reputation: 31
I am new to Sharepoint 2010 but not new to .Net programming. Here is a my situation, i have a large set of files to be uploaded into Sharepoint 2010 with metadata. I have decided to write a C# class library to handle the documentsets programatically. I have to use to DocumentSets and i was able to successfully create a documentset. Now i am stuck with the following:
Here is my code to create the documentset:
using (SPSite site = new SPSite(spURL))
{
using (SPWeb web = site.OpenWeb())
{
SPList docs = web.Lists["Documents"];
if (docs != null)
{
SPContentType docSetCT = docs.ContentTypes["Document Set"];
if (docSetCT != null)
{
Hashtable docsetProps = new Hashtable();
docsetProps.Add("New Docset", "New Docset");
DocumentSet docSet = DocumentSet.Create(docs.RootFolder, documentSetName, docSetCT.Id, docsetProps, true);
docs.Update();
}
}
}
}
Upvotes: 1
Views: 1741
Reputation: 59358
The list of helper methods for working with Document Sets:
How do I check if a document set already exists?
private static bool IsDocumentSetExist(SPList list,string docSetName)
{
var folderUrl = SPUrlUtility.CombineUrl(list.RootFolder.ServerRelativeUrl, docSetName);
var folder = list.ParentWeb.GetFolder(folderUrl);
return folder.Exists;
}
Usage:
var docSetExists = IsDocumentSetExist(docs, "New Docset");
How do I remove a document set?
private static void DeleteDocumentSet(DocumentSet docSet)
{
docSet.Folder.Delete();
}
Upvotes: 4