Question

I am able to add an app (List or Document Library) in SharePoint site by clicking 'gear icon -> site contents -> add an app -> Document Library'. And also I am asked only the name and description and the name itself is set as the url of the Document Library.

Is there any script or package that we can use to create Document Library through powershell or c#?

Était-ce utile?

La solution

PowerShell:

Add-PSSnapin microsoft.sharepoint.powershell
$web = Get-SPWeb http://server/sites/site
$list = $web.Lists.Add("Name", "Description", "Document Library")

C#:

Get an SPWeb object first. If you run your code from Feature Receiver and the feature is web scoped use the following:

var web = properties.Feature.Parent as SPWeb;
var list = web.Lists.Add("Name", "Description", "Document Library")

If you want to open new web, use the following:

using (SPSite site = new SPSite("SITE_COLLECTION_URL"))
{
    using (SPWeb web = site.OpenWeb("WEB_URL"))
    {
        var list = web.Lists.Add("Name", "Description", "Document Library")
    }
}   
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top