如何用代码创建文档库,并创建自定义列

protected void CreateDocLib()

{

SPSite site = SPContext.Current.Site;

SPWeb web = site.OpenWeb();

 

SPListTemplateType templateType = SPListTemplateType.DocumentLibrary;

Guid listId = web.Lists.Add("MyDocLibrary", null, templateType);

SPList list = web.Lists[listId];



    // create Text type new column called "My Column"

    list.Fields.Add("My Column", SPFieldType.Text, true);

 

    // make new column visible in default view

    SPView view = list.DefaultView;

    view.ViewFields.Add("My Column");

    view.Update();

}}

  

你可能感兴趣的:(自定义)