zoukankan      html  css  js  c++  java
  • 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的属性与内容成为可能。

  • 相关阅读:
    js动态绑定class(当前父级div下的子元素有没有这个class,有的话移除,没有的话添加)
    css 最简单的淡出淡出
    vue中注册全局组件并使用
    vue 安装完less之后报 Module build failed: TypeError: loaderContext.getResolve is not a function
    vue moment时间戳转日期的使用
    vue +element实现点击左侧栏目切换路由
    vue使用模板快速创建vue文件
    vue项目中全局使用vuex并注册全局属性
    npm ERR! A complete log of this run can be found in: npm ERR! D: ode ode_cache\_logs2020-06-13T08_12_35_648Z-debug.log
    cnpm的安装(超级详细版)
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/4882050.html
Copyright © 2011-2022 走看看