質問

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#?

役に立ちましたか?

解決

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")
    }
}   
ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top