SharePoint API测试系列——Records.BypassLocks测试
生活随笔
收集整理的這篇文章主要介紹了
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的屬性與內容成為可能。
轉載于:https://www.cnblogs.com/LanTianYou/p/4882050.html
總結
以上是生活随笔為你收集整理的SharePoint API测试系列——Records.BypassLocks测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: IOS中打开应用实现检查更新的功能
- 下一篇: RadASM的测试工程!