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

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.