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

  • 相关阅读:
    object-c之kvc kvo(人中有属性数组、Book对象,数组中装载Book对象)
    object-c之通知
    大文件复制时进行实时保存
    通讯录
    object-c中对文件操作
    Foundation 框架之——NSDate
    Foundation 框架之——NSDictionary、NSMutableDictionary
    Objective-C之数据类型和表达式
    C语言-函数
    Storyboard类介绍
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/4882050.html
Copyright © 2011-2022 走看看