・2014/11/21
SharePoint SDKを使用して C#でドキュメント管理を行なう方法
(Microsoft SharePoint 2013 SDKの使用方法、コンテンツを C#プログラムでいじくる方法)
Tags: [Windows開発]
●
SharePoint SDKを使用して C#でドキュメント管理を行なう方法
● SharePoint 2013サーバで補助的に動くアプリを作る
SharePoint クライアント オブジェクト モデル (CSOM)を使って SharePointサーバに接続して SharePointサーバに登録されたコンテンツを操作する。
.NET Framework 再頒布可能アセンブリ
● SharePoint Server 2013 Client Components SDK
SharePoint Server 2013 Client Components SDK
Version: 1
File Name:
sharepointclientcomponents_x64.msi 2.2MB
sharepointclientcomponents_x86.msi 1.8MB
Date Published: 9/3/2014
・Supported Operating System
Windows 7 Service Pack 1, Windows 8, Windows Server 2008 R2
SharePoint 2013 での適切な API セットの選択
● Visual Studio 2012で SharePoint 2013用アプリを作成する方法
Visual Studio 2012 で SharePoint 2013 用アプリ プロジェクトを作成すると, .NET Framework アセンブリ、Microsoft.SharePoint.Client.Runtime.dll、および Microsoft.SharePoint.Client.dllがプロジェクトに自動的に追加されます。
他の種類のプロジェクト (.NET Framework アプリケーションやコンソール アプリケーションなど) の場合は、これらの参照を追加する必要があります。
・参照設定に追加指定する DLL
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll
C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll
・作成したアプリを配布する場合は VS2012プロジェクトの参照エリアの該当 DLLのプロパティの [ローカル コピー]を選択して値を [True]にします。
コンパイルしてビルドしたディレクトリに DLLがコピーされるので配布時に楽です。
● SharePoint Client APIの使い方はこれが参考になる。
[方法] SharePoint 2013 のクライアント ライブラリ コードを使用して基本的な操作を完了する
・Web サイトのプロパティを取得する
SharePoint Web サイトのタイトルを取得します。
using System;
using System.Text;
using Microsoft.SharePoint.Client;
namespace SharePointTest1
{
class Program
{
static void Main(string[] args)
{
// Starting with ClientContext, the constructor requires a URL
// to the server running SharePoint.
ClientContext context = new ClientContext("http://SiteUrl");
// The SharePoint web at the URL.
Web web = context.Web;
// We want to retrieve the web's properties.
context.Load(web);
// Execute the query to the server.
context.ExecuteQuery();
// Now, the web's properties are available and we could display
// web properties, such as title.
System.Console.WriteLine("SharePoint Web Title: " + web.Title);
System.Console.ReadLine();
}
}
}
・Web 内のすべての SharePointリストを取得する
SharePoint Webサイト内のすべての SharePointリストを取得します。
System.Linq用の usingステートメントを追加する必要があります。
using System;
using System.Text;
using System.Linq;
using Microsoft.SharePoint.Client;
namespace SharePointTest2
{
class Program
{
static void Main(string[] args)
{
// Starting with ClientContext, the constructor requires a URL to the
// server running SharePoint.
ClientContext context = new ClientContext("http://SiteUrl");
// The SharePoint web at the URL.
Web web = context.Web;
// Retrieve all lists from the server.
// For each list, retrieve Title and Id.
context.Load(web.Lists,
lists => lists.Include(list => list.Title,
list => list.Id));
// Execute query.
context.ExecuteQuery();
// Enumerate the web.Lists.
foreach (List list in web.Lists)
{
System.Console.WriteLine("SharePoint List Title: " + list.Title);
}
System.Console.ReadLine();
}
}
}
・SharePointリストからアイテムを取得する
SharePointリスト内のアイテムを取得します。
Microsoft.SharePoint.Client.QueryExpression用の using ステートメントも追加する必要があります。
using System;
using System.Text;
using System.Linq;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.QueryExpression;
namespace SharePointTest3
{
class Program
{
static void Main(string[] args)
{
// Starting with ClientContext, the constructor requires a URL to the
// server running SharePoint.
ClientContext context = new ClientContext("http://SiteUrl");
// Assume the web has a list named "Announcements".
List announcementsList = context.Web.Lists.GetByTitle("Announcements");
// This creates a CamlQuery that has a RowLimit of 100,
// and also specifies Scope="RecursiveAll"
// so that it grabs all list items, regardless of the folder they are in.
CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
ListItemCollection items = announcementsList.GetItems(query);
// Retrieve all items in the ListItemCollection from List.GetItems(Query).
context.Load(items);
context.ExecuteQuery();
foreach (ListItem listItem in items)
{
// We have all the list item data. For example, Title.
System.Console.WriteLine("SharePoint ListItem Title: " + listItem["Title"]);
}
System.Console.ReadLine();
}
}
}
※ここで言う「アイテム」と言うのが SharePointに登録した「コンテンツ(ファイル)」と対応し、上記リスト中の ListItemがそれになる。
listItem変数の中の引数は SPBuiltInFieldIdで定義されており、ユーザー側でも追加する事が可能。
・SPBuiltInFieldId fieldsの主な値
SPBuiltInFieldId class
SPBuiltInFieldId fields
listItem["ID"] DBで言う所のレコード ID
listItem["Title"] コンテンツのタイトル
listItem["FSObjType"] コンテンツの種類 0=ファイル、1=ディレクトリ
listItem["FileRef"] コンテンツのフルパス "/hoge/xxxx/yyyy/zzzz.txt"
listItem["FileDirRef"] 親ディレクトリ "/hoge/xxxx/yyyy"
listItem["FileLeafRef"] ファイル名/ ディレクトリ名 "zzzz.txt"
● SharePointのアップロードするファイルのサイズ制限
SharePointのアップロードするファイルのサイズ制限は 2097152バイト(2MB)で、バイナリデータの場合は Base64でエンコードするので大体 1.6MBとなる。
サイズ制限を回避する方法は下記の Japan SharePoint Support Team Blogを参照する。
SharePoint Online/On-Premises 環境に対してプログラミングで大きなファイルをアップロードする
SharePointの CSOM (または REST) で 1.6 MB 以上のファイルをアップロードできない。
client.svc において、サービス メッセージの最大サイズとして指定されたサイズに起因する。
SPClientRequestServiceSettings.MaxParseMessageSize property
The max size in bytes of the message to be parsed.
MaxReceivedMessageSize
とは別物。
SharePoint 2010 RESTサービスである ListData.svcを使用してファイルをアップロードしても、10485760バイトを超えると同じエラーです。
SharePoint Foundation 2010 最大メッセージ サイズの増加
● SharePoint Clientからユーザー プロファイル プロパティを取得する方法
[方法] SharePoint 2013 の .NET クライアント オブジェクト モデルを使用してユーザー プロファイル プロパティを取得する
アセンブリへの参照を追加
Microsoft.SharePoint.Client
Microsoft.SharePoint.ClientRuntime
Microsoft.SharePoint.Client.UserProfiles
UserProfiles.UserProfilePropertiesForUser
GetUserProfilePropertiesFor
・SharePoint 2013のすべてのユーザー プロファイル プロパティの取得
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;
namespace UserProfilesCSOM
{
class Program
{
static void Main(string[] args)
{
// Replace the following placeholder values
// with the target SharePoint site and target user.
const string serverUrl = "http://serverName/";
const string targetUser = "domainName\\userName";
// Connect to the client context.
ClientContext clientContext = new ClientContext(serverUrl);
// Get the PeopleManager object
// and then get the target user's properties.
PeopleManager peopleManager = new PeopleManager(clientContext);
PersonProperties personProperties = peopleManager.GetPropertiesFor(targetUser);
// Load the request and run it on the server.
// This example requests only the AccountName and UserProfileProperties
// properties of the personProperties object.
clientContext.Load(personProperties, p => p.AccountName,
p => p.UserProfileProperties);
clientContext.ExecuteQuery();
foreach (var property in personProperties.UserProfileProperties)
{
Console.WriteLine(string.Format("{0}: {1}",
property.Key.ToString(), property.Value.ToString()));
}
Console.ReadKey(false);
// TODO: Add error handling and input validation.
}
}
}
● SharePoint 2013での「 いいね」と「 コメント」
SharePoint Server 2013 でのソーシャル コンピューティングの用語と概念
SharePoint 2013での「 いいね」と「 コメント」はソーシャルフィードを用いて実装されている。
[方法] SharePoint 2013 で .NET クライアント オブジェクト モデルを使用して投稿の作成と削除、およびソーシャル フィードの取得を行う
SocialFeedManager
ClientResult socialThread = GetFullThread(ThreadId);
socialThread.Value.TotalReplyCount コメントの件数
socialThread.Value.RootPost.LikerInfo.TotalCount いいねの件数
SocialPostLikerInfo property
SocialPostActorInfoTotalCount property
● SharePoint Online Client Components SDK
接続先が SharePoint Onlineの場合
SharePoint Online Client Components SDK
Version: 1
File Name:
sharepointclientcomponents_x64.msi 1.7MB
sharepointclientcomponents_x86.msi 1.7MB
Date Published: 9/3/2014
● SharePoint Foundation 2010 Client Object Model
接続先が SharePoint 2010の場合
SharePoint Foundation 2010 Client Object Model Redistributable
Version: 1.0
File Name:
SPClient_x64.msi 466KB
SPClient_x86.msi 466KB
Date Published: 11/3/2010
● SharePoint Foundation 2010 Client Object Model Redistributable Service Pack 2: KB2687467
SharePoint Foundation 2010 Client Object Model Redistributable Service Pack 2 (SP2)には、セキュリティ、パフォーマンス、および安定性の向上のための新しい更新プログラムが含まれています。また、この SP は以前公開されたすべての更新プログラムのロールアップです。
KB Articles: KB2687467
Service Pack 2 for SharePoint Foundation 2010 Client Object Model Redistributable (KB2687467) 32-Bit Edition
Version: 1.0
File Name:
spclientsp2010-kb2687467-fullfile-x86-en-us.exe 1.7MB
Date Published: 7/18/2013
Service Pack 2 for SharePoint Foundation 2010 Client Object Model Redistributable (KB2687467) 64-Bit Edition
Version: 1.0
File Name:
spclientsp2010-kb2687467-fullfile-x64-en-us.exe 1.7MB
Date Published: 7/18/2013
● Linq、統合言語クエリ
LINQ, Language INtegrated Query リンクと発音
.NET Framework 3.5において、様々な種類のデータ集合に対して標準化された方法でデータを問い合わせる(クエリ)ことを可能にするために、言語に統合された機能のことである。開発ツールはVisual Studio 2008から対応している。
Tags: [Windows開発]
[HOME]
|
[BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c)
2014 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator
http://www.neko.ne.jp/~freewing/software/sharepoint_2013_sdk/