Reputation: 1640
Is there a way to easily duplicate a SharePoint list code wise?
Upvotes: 3
Views: 2899
Reputation: 15912
Judging from the SharePoint tag, I'm assuming you meant to ask "How do I copy a SharePoint list (SPList) programmatically?"
Without testing it (or even trying to compile it), I would do something like:
SPWeb web; /* add code to initialize to current web */
SPList sourceList = web.Lists["nameOfSourceList"];
sourceList.SaveAsTemplate("templateFNM.stp", "tempList", "tempListDescription",
true /* include list content */);
SPListTemplate template = web.ListTemplates["tempList"];
web.Lists.Add("newListName", "newListDescription", template);
web.Update();
SPList newList = web.Lists["newListName"];
Also, here's a link to a blog post that achieves the same accross web applications.
And finally a word of advice: you'll get better search results if you use "programmatically" instead of "code wise".
Hope this helps.
Upvotes: 5