首先说一下什么是记录管理:这里有详细的说明

在 网站设置-》网站集管理-》网站集功能 中启用 “现场记录管理”

启用现场记录管理后在 网站管理 中多了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 declared
object 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 IsRecord
Console.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 ListPolicySettings
listPolicySettings = 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 it
if (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 one
if (retentionPolicy == null)
{
policy.Items.Add(Expiration.PolicyId, policyXml);
policy.Update();
}
else
{
retentionPolicy.CustomData = policyXml;
retentionPolicy.Update();
} //Return back policy XML to make sure it worked
retentionPolicy = 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 = "";
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 > )
{
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();
}

sharepoint 2010 记录管理 对象模型的更多相关文章

  1. SharePoint 2010 常用技巧及方法总结

    1.代码调试确定进程cd c:\windows\system32\inetsrvappcmd list wppause注:保存成批处理文件,查看进程.bat,用的时候双击即可 2.类似列表新建打开方式 ...

  2. SharePoint 2010 最佳实践学习总结------第1章 SharePoint Foundation开发基础

    ----前言 这段时间项目出在验收阶段,不是很忙,就潜心把SharePoint学一下,不求有多深刻,初衷只是先入门再说.后续会发布一系列的学习总结.主要学习的书籍为<SharePoint2010 ...

  3. 自定义和扩展 SharePoint 2010 Server 功能区

    了解构成 SharePoint 2010 服务器功能区的组件以及如何通过演练两个功能区自定义项方案来自定义功能区. 适用范围: Microsoft SharePoint Foundation 2010 ...

  4. SharePoint 2010 文档管理系列

    前言,这是自己第一次写一个系列的文档,本来想使用SharePoint 2013版本,但是碍于SharePoint 2013对于硬件要求过高,自己的笔记本无法承受,所以退而求其次选择了在SharePoi ...

  5. SharePoint 2010 文档管理之过期归档工具

    前言:使用过SharePoint的人都知道,SharePoint对于操作是便捷的,但是对于数据量承载却是不令人满意的,这样,就要求我们需要更加合理的使用,规范大家的使用规则和习惯,所以,定期清理不必要 ...

  6. 在SharePoint 2010 母版页里添加自定义用户控件

    在SharePoint 2010 母版页里添加自定义用户控件(译) 使用自定义用户控件的好处: 1.容易部署:2.易于控制显示或隐藏. (在使用的过程中)可能要面对的问题是:如何在用户控件里使用Sha ...

  7. SharePoint 2010顶部链接导航栏的详细操作

    转:http://www.360sps.com/Item/UseTopLink.aspx 在SharePoint 2010环境的页面中,导航链接总体上可以分为两类,一类是显示在左侧的快速启动栏,另一类 ...

  8. 在 SharePoint 2010 中访问数据

    转:http://blog.banysky.net/?p=81001 数据访问的关键方法有哪些? | 使用查询类 | 使用 SPQuery | 使用 SPSiteDataQuery | 使用 LINQ ...

  9. SharePoint 2010 -- Silverlight托管客户端模型简单示例

    Silverlight托管客户端模型,是SharePoint2010推出的三种客户端模型".NET托管"."ECMAScript"."Sliverli ...

随机推荐

  1. 【Ray Tracing in One Weekend 超详解】 光线追踪1-7 Dielectric 半径为负,实心球体镂空技巧

    今天讲这本书最后一种材质 Preface 水,玻璃和钻石等透明材料是电介质.当光线照射它们时,它会分裂成反射光线和折射(透射)光线. 处理方案:在反射或折射之间随机选择并且每次交互仅产生一条散射光线 ...

  2. BeagleBone Black教程之BeagleBone Black设备的连接

    BeagleBone Black教程之BeagleBone Black设备的连接 BeagleBone Black开发前需要准备的材料 经过上面的介绍,相信你已经对BeagleBone有了大致的了解, ...

  3. 网络与多线程---OC中多线程使用方法(一)

    小编在此之前,通过一个小例子,简单的形容了一下进程与线程之间的关系,现在网络编程中的多线程说一下!!! *进程的基本概念 每一个进程都是一个应用程序,都有自己独立的内存空间,一般来说一个应用程序存在一 ...

  4. LDO current regulator for power LED

    LDO current regulator for power LED Challenge You've got a power LED? Great! Build a flash light! Wh ...

  5. svn 迁移到 git 仓库并保留 commit 历史记录

    1.svn 转换为 git(会提示,让你输入先前 svn 的账号与密码) # 切换至 本地项目目录 cd /Users/jianbao/PhpStormProjects/fiisoo/ # 克隆 sv ...

  6. OFbiz--简单介绍

    一.简单介绍 OFBiz是一个很著名的电子商务平台,是一个很著名的开源项目,提供了创建基于最新J2EE/XML规范和技术标准,构建大中型企业级.跨平台.跨数据库.跨应用server的多层.分布式电子商 ...

  7. Cocos2d-x3.0下实现循环列表

    本文的实现是參照我之前在做iOS时实现的一个能够循环的列表这里用C++重写一遍. 效果: 原文地址:http://blog.csdn.net/qqmcy/article/details/2739301 ...

  8. WebStorm中使用ES6的几种方式

    本篇总结几种在WebStorm下使用ES6的方式. 首先要选择Javascript的版本.依次点击"File","Settings","Languag ...

  9. AngularJS路由系列(5)-- UI-Router的路由约束、Resolve属性、路由附加数据、路由进入退出事件

    本系列探寻AngularJS的路由机制,在WebStorm下开发.主要包括: ● UI-Router约束路由参数● UI-Router的Resolve属性● UI-Router给路由附加数据● UI- ...

  10. AdjustWindowRect 与 SetWindowPos

    这两个函数经常一起使用,所以放到一起讲: 1 AdjustWindowRect 函数功能:该函数依据所需客户矩形的大小,计算需要的窗口矩形的大小.计算出的窗口矩形随后可以传递给CreateWindow ...