Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate a SharePoint list

Tags:

sharepoint

Is there a way to easily duplicate a SharePoint list code wise?

like image 852
chicken Avatar asked Sep 16 '26 15:09

chicken


1 Answers

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.

like image 87
vitule Avatar answered Sep 18 '26 19:09

vitule



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!