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的属性与内容成为可能。

  • 相关阅读:
    微信小程序,地址助手
    Cordova 项目,升级 Xcode 从 10.3 到 11.0 扫坑日记
    MySQL 重启提示超出可打开文件数限制|Buffered warning: Changed limits: max_open_files: 1024
    “基于名称”的虚拟主机支持
    阿里云免费证书配置
    微信小程序开发常见问题
    webpack 打包压缩 ES6文件报错UglifyJs + Unexpected token punc «(», expected punc «:»
    本地不安装webpack,找不到webpack包
    Hdu1097(计算a的b次幂最后一位数值)
    计算某天是所在年的第几天
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/4882050.html
Copyright © 2011-2022 走看看