This article describes SharePoint 2013/2010 moving list items within a list or document library. Document and directory location and keep system fields such as last modify by to be resolved in a constant manner.
Recently encountered a customer needs to move list items, document and directory locations within a list or document library and keep system fields such as last modify by unchanged.
The study came out. Dare not to enjoy alone. Share it with the footwear participants:
Using microsoft.sharepoint;using system;using system.collections.generic;using system.linq;using System.Text;using System.threading.tasks;namespace movesplistitemtool{class Program {static void Main (string[] args) { Spsecurity.runwithelevatedprivileges (delegate () {using (SPSite site = new SPSite ("H ttp://sp2013/")) {site. Allowunsafeupdates = true; using (SPWeb Web = site. OpenWeb ()) {SPList list = web. lists["Documents"]; var itemneedtomove = list. GetItemByID (7); Moveitemto (Itemneedtomove, "Testdocumentset"); } } }); Console.WriteLine ("done!"); Console.readkey (); }//Path parameter instance: Folder1, folder1/folder2 public static void Moveitemto (SPListItem item, string path) {Switch (item. Filesystemobjecttype) {case SPFileSystemObjectType.Folder:var NewFolder = s Tring. Format ("{0}/{1}/{2}", item. PARENTLIST.ROOTFOLDER.URL, Path, item. Folder.name); Item. Folder.moveto (NewFolder); Break Case SPFileSystemObjectType.File:if (item. FILE = = null) {var file = Item. Web.getfile (item. URL); var Newfilepath = string. Format ("{0}/{1}/{2}_.000", item. PARENTLIST.ROOTFOLDER.URL, Path, item.id); File. MoveTo (Newfilepath); } else {var file = Item. Web.getfile (item. URL); var Newfilepath = string. Format ("{0}/{1}/{2}", item. PARENTLIST.ROOTFOLDER.URL, Path, item. File.name); File. MoveTo (Newfilepath); } Break } } }}
SharePoint 2013/2010 moves list items, document and directory locations within a list or document library and keeps the system fields, such as last modify by, intact