zoukankan      html  css  js  c++  java
  • SharePoint 2013/2010 在一个列表或文档库内移动列表项,文档和目录位置而保持last modify by 等系统字段保持不变

    本文讲述SharePoint 2013/2010 在一个列表或文档库内移动列表项。文档和目录位置而保持last modify by 等系统字段保持不变的解决方式。

    近期遇到客户一个需求,在一个列表或文档库内移动列表项,文档和目录位置而保持last modify by 等系统字段保持不变。

    研究出来了。不敢独享。特此共享出来给同鞋们做參考:

    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("http://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 參数实例: Folder1,  Folder1/Folder2
            public static void MoveItemTo(SPListItem item, string path)
            {   
                switch (item.FileSystemObjectType)
                {
                    case SPFileSystemObjectType.Folder:
                        var newFolder = string.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;
                }
            }
        }
    }
    


     

  • 相关阅读:
    无线渗透(六)WPS、伪造AP
    无线渗透(五)COWPATTY 破解密码
    无线渗透(四)WPA攻击
    无线渗透(一)密钥交换
    metsploit 渗透测试指南
    本地提权汇总
    电子取证-活取证2
    如何利用Python网络爬虫抓取微信好友数量以及微信好友的男女比例
    如何在Centos官网下载所需版本的Centos——靠谱的Centos下载教程
    如何利用Python词云和wordart可视化工具对朋友圈数据进行可视化展示
  • 原文地址:https://www.cnblogs.com/blfbuaa/p/6741730.html
Copyright © 2011-2022 走看看