[C#.NET][Sharepoint 2013] 封存檔案 - Use Record Center

[C#.NET][Sharepoint 2013] 封存檔案 - Use Record Center

續上篇,http://www.dotblogs.com.tw/yc421206/archive/2014/06/09/145460.aspx

使用情境:

  • 當文件進入封存後,無法修改該檔案的任何屬性,包含內容,不能夠下載檔案,文件庫只會留下已經封存的 Hyper-Link,若使用者有權限可以連結至 Record Center 開啟該檔案

PS.CSOM 目前不支援 SendToOfficialFile ,所以在這裡使用的是 Server-Site Object Model

本文章節

    1. Create Record Center
    2. Get Submission Points
    3. Creating New “Send To” Location at Configure Send To Connections
    4. Test Send To Connection at Documents Library
    5. 使用 Server API SPFile.SendToOfficialFile 將檔案封存

Create Record Center

image

image

 

建立完成,如下圖:

image

 

Get Submission Points

image

image

 

取得URL

http://sps2013/sites/record/_vti_bin/OfficialFile.asmx

image

 

Creating New “Send To” Location at Configure Send To Connections

image

填入相關訊息,

Display name:Send to Record Center

Send To URL:http://sps2013/sites/record/_vti_bin/OfficialFile.asmx

Send To action:Move and Leave a Link

image

 

Test Send To Connection at Documents Library

image

image

 

image


使用 Server API SPFile.SendToOfficialFile 將檔案封存

準備環境

  1. Install Sharepoint Foundation 2013
  2. Add Reference Microsoft.SharePoint.dll
  3. Server-Side API:http://msdn.microsoft.com/en-us/library/cc768559.aspx
  4. 依照上述步驟建立 Record Center
    1. Create Record Center
    2. Get Submission Points
    3. Creating New “Send To” Location at Configure Send To Connections

 

開發重點

  1. 調用 SPFile.SendToOfficialFile 方法

 

完整範例如下:

 

using System;
using System.IO;

namespace ConsoleApplication1
{
    internal class Program
    {
        private const string s_TopSite = @"http://sps2013";
        private const string s_SubSite = @"/csomapi";
        private const string s_List = @"Documents";

        private const string s_FileName = @"myDoc.docx";

        private static void Main(string[] args)
        {
            addFile();
            sendToRecord();
        }

        private static void addFile()
        {
            using (SPSite site = new SPSite(s_TopSite))
            {
                using (SPWeb web = site.OpenWeb(s_SubSite))
                {
                    SPFolder list = web.Lists[s_List].RootFolder;
                    FileStream fileStream = File.OpenRead(s_FileName);
                    SPFile file = list.Files.Add(s_FileName, fileStream, true);
                    file.Update();
                }
            }

            Console.WriteLine("addFile Successful ,Press any key continue");
            Console.ReadKey();
        }

        private static void sendToRecord()
        {
            using (SPSite site = new SPSite(s_TopSite))
            {
                using (SPWeb web = site.OpenWeb(s_SubSite))
                {
                    SPFolder list = web.Lists[s_List].RootFolder;
                    SPFileCollection files = list.Files;

                    foreach (SPFile file in files)
                    {
                        SPListItem item = file.Item;
                        Console.WriteLine("Found file:{0}", item.Name);

                        if (item.Name == s_FileName)
                        {
                            string additionalInformation = null;
                            OfficialFileResult result = file.SendToOfficialFile(out additionalInformation);
                            Console.WriteLine("result:{0}\r\nadditionalInformation:{1}", result, additionalInformation);
                            break;
                        }
                    }
                }
            }
            Console.WriteLine("sendToRecord Successful ,Press any key continue");
            Console.ReadKey();
        }
    }
}

執行結果如下圖

image


本文出自:http://www.dotblogs.com.tw/yc421206/archive/2014/06/10/145466.aspx

若有謬誤,煩請告知,新手發帖請多包涵


Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET

Image result for microsoft+mvp+logo