In this article I am going to show how you
can Add/Edit SharePoint Document Library programmatically. Here is the sample
code;
Save Document Library
public bool SaveList(string LibraryName, string Description, string type,int templeteid)Update Document Library
{try{SPSite site = new SPSite(URL)using (SPWeb web = site.OpenWeb()){SPDocTemplate docTemplate = (from SPDocTemplate dt in web.DocTemplateswhere dt.Type == templeteidselect dt).FirstOrDefault();web.Lists.Add(LibraryName, Description, web.ListTemplates["Document Library"], docTemplate);}}catch (Exception ex){MessageBox.Show("Coundn't create the new list" + Environment.NewLine + ex.Message, "Message");return false;}return true;}
public bool UpdateList(string LibraryName, string Description, string type, int templeteid){try{SPSite site = new SPSite(URL)using (SPWeb web = site.OpenWeb()){Guid id = new Guid(DocID);SPList List = web.Lists[id];List.Title = LibraryName;List.Description = Description;List.EnableVersioning = true;List.Update();}}catch (Exception ex){MessageBox.Show("Coundn't create the new list" + Environment.NewLine + ex.Message, "Message");return false;}return true;}
Document Template id
- None-100
- Microsoft Word 97-2003 document – 101
- Microsoft Excel 97-2003 spreadsheet-103
- Microsoft PowerPoint 97-2003 – 104
- Microsoft Word document-121
- Microsoft Excel spreadsheet-122
- Microsoft PowerPoint presentation-123
- Microsoft OneNote 2010 Notebook- 111
- Microsoft SharePoint Designer Web page - 102
- Basic page-105
- Web Part page-106
No comments:
Post a Comment