日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sharepoint 2010 记录管理 对象模型

發布時間:2023/12/15 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sharepoint 2010 记录管理 对象模型 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先說一下什么是記錄管理:這里有詳細的說明

在 網站設置-》網站集管理-》網站集功能 中啟用 “現場記錄管理”

啟用現場記錄管理后在 網站管理 中多了2個功能“內容管理器設置” 和“內容管理器規則”

選擇一個列表的庫設置-》記錄聲明設置:

然后再文檔-》項目中會出現 申明記錄

聲明為記錄后 默認是不能修改和刪除, 如果要取消聲明 也需要相應的代碼

聲明為記錄后:

如果我們直接刪除會有 聲明后果了:

其實 文檔的修改也有類似的情況。為什么會這樣了?

讓我們定位到 網站設置-》網站集管理-》記錄聲明設置:

1)聲明記錄和取消聲明

聲明記錄方法:?Records.DeclareItemAsRecord(item)

取消聲明記錄:?Records.UndeclareItemAsRecord(item)

這里需要引用一些相關的DLL:

Microsoft.Office.DocumentManagement

Microsoft.Office.Policy

主要代碼如下:

private static void RecordTest(){using (SPSite site = new SPSite(siturl)){SPWeb web = site.RootWeb;SPList list = web.GetList(SharePointListURL);SPFolder folder = web.Folders[SharePointListURL];Stream fileStream = File.Open(filePath, FileMode.Open);SPFile file = list.RootFolder.Files.Add(fileSharePointURL, fileStream);SPListItem item = file.Item;file.Update();Console.WriteLine("In Place Records enabled: " + Records.IsInPlaceRecordsEnabled(site).ToString());//Declare the item as a record Records.DeclareItemAsRecord(item);//Make sure it declaredobject dateObject = item[Expiration.ExpirationDateFieldInternalName];if (dateObject == null){Console.WriteLine("Not declared!");}else{DateTime date = (DateTime)dateObject;Console.WriteLine("Declared Expiration Date: " + date.ToShortDateString() + " " + date.ToShortTimeString());//Also show if Record using IsRecordConsole.WriteLine("IsRecord: " + Records.IsRecord(item));//Could also use OnHold to check if on hold }//Undeclare the object Records.UndeclareItemAsRecord(item);web.Close();}}

2)創建保留計劃

如果想在列表上創建一個保留策略,首先要檢查列表手否有自定義策略,這個需要Microsoft.Office.RecordsManagement.InformationPolicy.ListPolicySettings對象的ListHasPolicy屬性,,返回值表示列表是否具有自定義策略。要想將列表設置為使用一個自定義策略,只需要將UseListPolicy設置為true,然后調用update方法。主要代碼如下:

private static void PolicyList(){using (SPSite site = new SPSite(siturl)){SPWeb web = site.RootWeb;SPList list = web.GetList(SharePointListURL);SPFolder folder = web.Folders[SharePointListURL];SPWeb parentWeb = list.ParentWeb;SPList parentList = parentWeb.Lists[folder.ParentListId];ListPolicySettings listPolicySettings = new ListPolicySettings(parentList);string policyXml = @"<Schedules nextStageId='4' default='false'><Schedule type='Default'><stages><data stageId='1' recur='True' offset='6' unit='months'><formula id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Formula.BuiltIn'><number>6</number><property>Created</property><period>months</period></formula><action type='action' id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Action.DeletePreviousVersions' /></data><data stageId='2'><formula id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Formula.BuiltIn'><number>6</number><property>Modified</property><period>months</period></formula><action type='action' id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Action.Record' /></data></stages></Schedule><Schedule type='Record'><stages><data stageId='3'><formula id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Formula.BuiltIn'><number>3</number><property>Created</property><period>years</period></formula><action type='action' id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Action.Delete' /></data></stages></Schedule></Schedules>";if (!listPolicySettings.UseListPolicy){//Enable Location Based Policy if it isn't enabled listPolicySettings.UseListPolicy = true;listPolicySettings.Update();//Refresh to get the updated ListPolicySettingslistPolicySettings = new ListPolicySettings(parentList);} listPolicySettings.SetRetentionSchedule(folder.ServerRelativeUrl, policyXml, "My Custom Retention");listPolicySettings.Update();Console.WriteLine(listPolicySettings.GetRetentionSchedule(folder.ServerRelativeUrl));web.Close();}}

這里的保留策略是與列表綁定的,一搬建議與內容類型綁定。

private static void PolicyContentType(){using (SPSite site = new SPSite(siturl)){SPWeb web = site.RootWeb;SPList list = web.GetList(SharePointListURL);SPFolder folder = web.Folders[SharePointListURL];SPWeb parentWeb = list.ParentWeb;SPList parentList = parentWeb.Lists[folder.ParentListId];ListPolicySettings listPolicySettings = new ListPolicySettings(parentList);string policyXml = @"<Schedules nextStageId='4' default='false'><Schedule type='Default'><stages><data stageId='1' recur='True' offset='6' unit='months'><formula id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Formula.BuiltIn'><number>6</number><property>Created</property><period>months</period></formula><action type='action' id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Action.DeletePreviousVersions' /></data><data stageId='2'><formula id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Formula.BuiltIn'><number>6</number><property>Modified</property><period>months</period></formula><action type='action' id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Action.Record' /></data></stages></Schedule><Schedule type='Record'><stages><data stageId='3'><formula id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Formula.BuiltIn'><number>3</number><property>Created</property><period>years</period></formula><action type='action' id='Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration.Action.Delete' /></data></stages></Schedule></Schedules>";SPContentType contentType = web.ContentTypes["文檔"];Policy policy = Policy.GetPolicy(contentType);//Check to see if it exists, if not create itif (policy == null){Policy.CreatePolicy(contentType, null);policy = Policy.GetPolicy(contentType);}PolicyItem retentionPolicy = policy.Items[Expiration.PolicyId];//See if a policy already exists, if not create oneif (retentionPolicy == null){policy.Items.Add(Expiration.PolicyId, policyXml);policy.Update();}else{retentionPolicy.CustomData = policyXml;retentionPolicy.Update();}//Return back policy XML to make sure it workedretentionPolicy = policy.Items[Expiration.PolicyId];Console.WriteLine("Policy XML: " + retentionPolicy.CustomData.ToString());web.Close();}}

運行后的結果如下:

首先定位到“網站內容類型” -》文檔-》信息管理策略設置:

?3)創建組織器規則

必須使用Microsoft.Office.RecordsManagement.RecordsRepository.EcmDocumentRoutingWeb對象。必須在站點功能設置中激活內容組織器功能.

網站操作->管理網站功能:

如果想基于一個唯一的屬性實現自動折疊,那么可以使用DocumentRouterAutoFolderSettings類,主要代碼如下:

public static void PolicyTest(){using (SPSite site = new SPSite(siturl)){SPWeb web = site.RootWeb;SPList list = web.GetList(SharePointListURL);SPFolder folder = web.Folders[SharePointListURL];SPWeb parentWeb = list.ParentWeb;EcmDocumentRoutingWeb router = new EcmDocumentRoutingWeb(web);foreach (EcmDocumentRouterRule rule in router.RoutingRuleCollection){string s = "Alias:" + rule.Aliases + " AFP:" + rule.AutoFolderPropertyName + " Cond:" + rule.ConditionsString + " CTS:"+ rule.ContentTypeString + " CR:" + rule.CustomRouter + " PRI:" + rule.Priority + " TP:" + rule.TargetPath+ " Name:" + rule.Name + " Desc:" + rule.Description;DocumentRouterAutoFolderSettings autoFolder = rule.AutoFolderSettings;s += "name Format: " + autoFolder.AutoFolderFolderNameFormat+ " PropID:" + autoFolder.AutoFolderPropertyId.ToString()+ " InternalName:" + autoFolder.AutoFolderPropertyInternalName+ " PropName:" + autoFolder.AutoFolderPropertyName+ " TypeasString:" + autoFolder.AutoFolderPropertyTypeAsString+ " MaxItem:" + autoFolder.MaxFolderItems.ToString()+ " Term:" + autoFolder.TaxTermStoreId.ToString();Console.WriteLine(s);}SPContentType contentType = web.ContentTypes["問題"];string contentString = contentType.Id.ToString() + "|" + contentType.Name;SPField fieldname = contentType.Fields["標題"];string fieldNamestring = fieldname.Id.ToString() + "|" + fieldname.InternalName + "|" + fieldname.Title; EcmDocumentRouterRule newRule = new EcmDocumentRouterRule(web);newRule.Name = "Custom Category Rule";newRule.Description = "Created by Gavin";newRule.Priority = "5";newRule.ContentTypeString = contentString;newRule.TargetPath = "/SiteCollectionDocuments";newRule.ConditionsString = @"<Conditions><Condition Column='8553196d-ec8d-4564-9861-3dbe931050c8|FileLeafRef|Name' Operator='IsNotEqual' Value='NotEqualTo' /><Condition Column='8553196d-ec8d-4564-9861-3dbe931050c8|FileLeafRef|Name' Operator='GreaterThan' Value='GreaterTha=' /><Condition Column='8553196d-ec8d-4564-9861-3dbe931050c8|FileLeafRef|Name' Operator='LessThan' Value='LessThan' /><Condition Column='8553196d-ec8d-4564-9861-3dbe931050c8|FileLeafRef|Name' Operator='GreaterThanOrEqual' Value='GreaterThanEqual' /><Condition Column='8553196d-ec8d-4564-9861-3dbe931050c8|FileLeafRef|Name' Operator='LessThanOrEqual' Value='LessThanOrEqua=' /><Condition Column='8553196d-ec8d-4564-9861-3dbe931050c8|FileLeafRef|Name' Operator='BeginsWith' Value='BeginsWith' /></Conditions>";SPField customField = contentType.Fields["說明"]; DocumentRouterAutoFolderSettings afaoler = newRule.AutoFolderSettings;afaoler.Enabled = true;afaoler.AutoFolderPropertyInternalName = customField.InternalName;afaoler.AutoFolderPropertyId = customField.Id;afaoler.AutoFolderPropertyName = customField.Title;afaoler.AutoFolderPropertyTypeAsString = customField.TypeAsString;afaoler.AutoFolderFolderNameFormat = "%1-%2"; newRule.Enabled = true;router.RoutingRuleCollection.Add(newRule);}}

運行結果如圖:

網站管理 ->內容管理器規則

不知道為什么這里用“問題”內容內型后規則不能編輯,之間用自定義的內容內型是沒有問題的。

正過代碼需要幾個常量定義

public const string siturl="http://center.beauty.com/";

private const string SharePointListURL = "http://center.beauty.com/Documents/";
private const string filePath = @"c:\demo.docx";
private const string fileSharePointURL = "http://center.beauty.com/Documents/demo.docx";

這里也附加一段 刪除自定義內容內型的代碼:

public static void RemoveContentType(){using (SPSite siteCollection = new SPSite(siturl)){using (SPWeb webSite = siteCollection.OpenWeb()){// Get the obsolete content type.SPContentType obsolete = webSite.ContentTypes["CustomDC"];// We have a content type.if (obsolete != null){IList<SPContentTypeUsage> usages = SPContentTypeUsage.GetUsages(obsolete);// It is in use.if (usages.Count > 0){Console.WriteLine("The content type is in use in the following locations:");foreach (SPContentTypeUsage usage in usages)Console.WriteLine(usage.Url);}// The content type is not in use.else{// Delete it.Console.WriteLine("Deleting content type {0}...", obsolete.Name);webSite.ContentTypes.Delete(obsolete.Id);}}// No content type found.else{Console.WriteLine("The content type does not exist in this site collection.");}}}Console.Write("\nPress ENTER to continue...");Console.ReadLine();} View Code

?

總結

以上是生活随笔為你收集整理的sharepoint 2010 记录管理 对象模型的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。