• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
秦大田的院子
博客园    首页    新随笔    联系   管理    订阅  订阅
使用OfficialFile webservice 进行管理规则上传文档到放置库归档

using System;
using System.Collections.Generic;
using System.IO;
using RecordsAdmission.OfficialFileService;

namespace RecordsAdmission
{
class Program
{
static void Main(string[] args)
{
string filePath = @"c:\contoso.docx";

RecordsRepository repository = new RecordsRepository();
repository.Url = "http://contoso/recordscenter/_vti_bin/officialfile.asmx";
repository.UseDefaultCredentials = true;
byte[] fileContent = File.ReadAllBytes(filePath);

List<OfficialFileService.RecordsRepositoryProperty> properties =
new List<OfficialFileService.RecordsRepositoryProperty>();
properties.Add(new OfficialFileService.RecordsRepositoryProperty()
{ Name = "Title", Type = "Text", Value = "ctypetest" });
properties.Add(new OfficialFileService.RecordsRepositoryProperty()
{ Name = "Name", Type = "Text", Value = "contosofs.docx" });
properties.Add(new OfficialFileService.RecordsRepositoryProperty()
{ Name = "Customer", Type = "Text", Value = "Contoso" });
properties.Add(new OfficialFileService.RecordsRepositoryProperty()
{ Name = "ContentType", Type = "Text", Value = "Sales Proposal" });

string sourceUrl = filePath;
string userName = @"sharepoint\administrator";

string result = repository.SubmitFile(fileContent, properties.ToArray(),
null, sourceUrl, userName);
Console.WriteLine(result);
Console.ReadLine();
}
}
}

 

 

创建规则

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
using Microsoft.Office.RecordsManagement.RecordsRepository;

namespace ContentOrganizerRules
{
class CreateRule
{
static void Main(string[] args)
{
string absoluteSiteUrl = "http://contoso/recordscenter/";
string ruleName = "Woodgrove Sales Proposals";
string ruleDescription = "Sample rule to organize documents";
string ruleLibraryName = "Sales Proposals";
string ruleFolderUrl = "Sales Proposals/Woodgrove";
string ruleContentTypeName = "Sales Proposal";

string conditionFieldId = "90d69139-483c-4872-8ce0-5884bd370513"; // SPField.Id
string conditionFieldInternalName = "Customer"; //SPField.InternalName
string conditionFieldTitle = "Customer"; //SPField.Title

string conditionOperator = "Equal";
string conditionFieldValue = "Woodgrove";

// Build the conditionSettings XML from the constants above.
string conditionXml =
String.Format(@"<Condition Column=""{0}|{1}|{2}"" Operator=""{3}"" Value=""{4}"" />",
conditionFieldId, conditionFieldInternalName, conditionFieldTitle,
conditionOperator,
conditionFieldValue);
string conditionsXml = String.Format("<Conditions>{0}</Conditions>", conditionXml);

// Grab the SPWeb object and the rules library.
using (SPSite contentOrganizerSiteCollection = new SPSite(absoluteSiteUrl))
{
SPWeb contentOrganizerSite = contentOrganizerSiteCollection.OpenWeb();
EcmDocumentRoutingWeb contentOrganizerSiteWrapper =
new EcmDocumentRoutingWeb(contentOrganizerSite);
SPContentType ruleContentType = contentOrganizerSite.ContentTypes[ruleContentTypeName];
SPList ruleLibrary = contentOrganizerSite.Lists[ruleLibraryName];

if (ruleLibrary.ContentTypes.BestMatch(ruleContentType.Id) == null)
{
throw new ArgumentException(String.Format(
"Ensure that the library {0} contains content type {1} before creating the rule",
ruleLibraryName,
ruleContentTypeName));
}

// Create a blank rule.
EcmDocumentRouterRule organizeDocument = new EcmDocumentRouterRule(contentOrganizerSite);

// Configure the rule.
organizeDocument.Name = ruleName;
organizeDocument.Description = ruleDescription;
organizeDocument.ContentTypeString = ruleContentType.Name;
organizeDocument.RouteToExternalLocation = false;
organizeDocument.Priority = "5";
organizeDocument.TargetPath =
contentOrganizerSite.GetFolder(absoluteSiteUrl + ruleFolderUrl).ServerRelativeUrl;
organizeDocument.ConditionsString = conditionsXml;

// Update the rule and commit changes.
organizeDocument.Update();
}
}
}
}

posted on 2020-04-17 09:27  秦大田的院子  阅读(153)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3