• SharePoint API测试系列——Records.BypassLocks测试


    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/

    对于SharePoint中已经是Record的Item,我们想要修改他的属性,这在UI界面是无法完成的:

    这时需要通过Records.BypassLocks API来完成。设计一个tool,利用Records.BypassLocks API来修改Recorded Items的属性(这里拿Title举例),界面如下:

    代码如下:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Utilities;
    //Assembly:  Microsoft.Office.Policy (in Microsoft.Office.Policy.dll)
    using Microsoft.Office.RecordsManagement.RecordsRepository;
    using Microsoft.SharePoint.Publishing;
    
    namespace BypassLocksTestTool
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void test_button_Click(object sender, EventArgs e)
            {
                try
                {
                    SPSecurity.RunWithElevatedPrivileges(delegate ()
                    {
                        SPSite site = new SPSite(siteURL_textBox.Text);
                        SPWeb web = site.RootWeb;
                        SPList list = web.Lists[listTitle_textBox.Text];
                        SPListItem item = list.Items[0];
                        Records.BypassLocks(item, delegate (SPListItem spListItem)
                        {
                            //Do your stuff here.
                            item["Title"] = itemTitle_textBox.Text;
                            item.Update();
                            if (list.Items[0].Title == itemTitle_textBox.Text)
                            {
                                testResult_richTextBox.Text = "Test result is passed! Now the first item's title is: " + list.Items[0].Title;
                                testResult_richTextBox.Select(0, testResult_richTextBox.Text.Length);
                                testResult_richTextBox.SelectionColor = Color.Green;
                            }
                            else
                            {
                                testResult_richTextBox.Text = "Test result is failed!";
                                testResult_richTextBox.Select(0, testResult_richTextBox.Text.Length);
                                testResult_richTextBox.SelectionColor = Color.Red;
                            }
                        });
                    });
                }
                catch (Exception ex)
                {
                    testResult_richTextBox.Text = ex.ToString();
                }
            }
        }
    }

    点击Test按钮进行测试,测试结果会回显到界面,如果Title的value完成了修改,则算测试通过;否则算测试失败。

    测试通过后,我们去SharePoint中查看Item的属性,结果和我们预期的一样,对应Item的Title属性值已经变为“SuperTylan”:

    这就是对于Records.BypassLocks API的使用与测试,它让我们修改locked recorded item的属性与内容成为可能。

  • 相关阅读:
    获取成本
    销售订单跟踪成本
    装机
    这就是用战术上的勤奋掩盖战略上的懒惰
    CPA-计划(参考)
    大帝名言
    BZOJ 2100: [Usaco2010 Dec]Apple Delivery spfa
    BZOJ 2834: 回家的路 Dijkstra
    BZOJ 4070: [Apio2015]雅加达的摩天楼 根号分治+spfa
    BZOJ 4152: [AMPPZ2014]The Captain Dijkstra+贪心
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/4882050.html
Copyright © 2020-2023  润新知