Share via


ServerDocument クラス (2007 System)

更新 : 2007 年 11 月

Microsoft Office Excel 2007 または Microsoft Office Word 2007 用のドキュメント レベルのカスタマイズの一部であるドキュメントに存在する、キャッシュされたデータおよびカスタマイズ情報へのアクセスを提供します。

名前空間 :  Microsoft.VisualStudio.Tools.Applications
アセンブリ :  Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0 (Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll 内)

構文

'宣言
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public NotInheritable Class ServerDocument _
    Implements IDisposable
'使用
Dim instance As ServerDocument
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class ServerDocument : IDisposable

解説

Excel または Word がインストールされていないコンピュータ上のドキュメント レベルのカスタマイズの特定部分を管理するには、ServerDocument クラスを使用します。

一般的なタスクを実行するには、ServerDocument クラスの次のメンバを使用します。

  • サーバー上のドキュメントのデータ キャッシュにあるデータへのアクセスやデータの変更を行うには、CachedData プロパティを使用します。

  • プログラムを使用してドキュメントにカスタマイズをアタッチしたり、ドキュメントからカスタマイズを削除したりするには、AddCustomization メソッドと RemoveCustomization メソッドを使用します。

  • ドキュメントに関連付けられた配置マニフェストの URL にアクセスしたり、URL を変更したりするには、DeploymentManifestUrl プロパティを使用します。

詳細については、「ServerDocument クラスによるサーバー上のドキュメントの管理」を参照してください。

使用するコンストラクタの選択

ServerDocument クラスを使用してドキュメント内のキャッシュされたデータや配置マニフェストの URL にアクセスするには、ServerDocument オブジェクトを作成する必要があります。

2 組の ServerDocument コンストラクタがあります。

  • 1 組は、メモリで既に開かれているドキュメントへのアクセスに使用します。

  • もう 1 組は、ディスク上にあるドキュメントへのアクセスに使用します。

メモリ内のドキュメントへのアクセス

メモリで既に開かれているドキュメントにアクセスするには、次のいずれかのコンストラクタを使用します。

これらのコンストラクタは、バイト配列、またはメモリ内のドキュメントを表す Stream を受け取ります。これは、HTTP プロトコルを使用して宛先にストリーム転送する前に、ドキュメント内のキャッシュされたデータやアプリケーション マニフェストを変更する場合に役立ちます。これらのコンストラクタを使用するには、ドキュメントに Visual Studio Tools for Office カスタマイズが含まれている必要があります。それ以外の場合、コンストラクタは CannotLoadManifestException 例外をスローします。

ディスク上のドキュメントへのアクセス

ディスク上のドキュメントにアクセスするには、次のいずれかのコンストラクタを使用します。

これらのコンストラクタは、開くドキュメントの完全パスを受け取ります。既定で、ドキュメントは読み取り/書き込みアクセスで開かれます。読み取り専用アクセスまたは書き込み専用アクセスでドキュメントを開くには、FileAccess パラメータを持つコンストラクタを使用します。

ServerDocument クラスの各種バージョンについて

Visual Studio Tools for Office は、Microsoft Office 2003 および 2007 Microsoft Office system のソリューションに対して、さまざまなバージョンの ServerDocument クラスを提供します。このバージョンの ServerDocument クラスは、Word 2007 と Excel 2007 のドキュメント レベルのプロジェクト テンプレートを使用して作成されたソリューションでのみ使用できます。

Word 2003 と Excel 2003 のプロジェクト テンプレートを使用して作成されたソリューションで機能させるためには、Microsoft.VisualStudio.Tools.Applications.Runtime 名前空間の ServerDocument クラスを使用します。

詳細については、「ServerDocument クラスによるサーバー上のドキュメントの管理」を参照してください。同じコード ファイルにある ServerDocument クラスの両方のバージョンを使用する方法を示すコード例については、「方法 : ServerDocument クラスの両方のバージョンを使用するコードを記述する」を参照してください。

次のコード例は、指定のドキュメントを読み込む新しい ServerDocument を作成し、ドキュメントにアタッチされた Visual Studio Tools for Office カスタマイズの配置マニフェストの URL を表示します。オブジェクトを作成する前に、コードは GetCustomizationVersion メソッドを使用して、Microsoft Visual Studio Tools for the Microsoft Office system (version 3.0 Runtime) を使用して作成されたカスタマイズであることを検証します。これは、このバージョンの ServerDocument クラスと互換性のある唯一のランタイムです。詳細については、「ServerDocument クラスによるサーバー上のドキュメントの管理」を参照してください。

この例では、Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll アセンブリと Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll アセンブリへの参照、およびコード ファイルの先頭に記述された Microsoft.VisualStudio.Tools.Applications 名前空間および Microsoft.VisualStudio.Tools.Applications.Runtime 名前空間に対する Imports ステートメント (Visual Basic の場合) または using ステートメント (C# の場合) が必要です。

Private Sub CreateServerDocumentFromPath(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            serverDocument1 = New ServerDocument(documentPath)
            MessageBox.Show("The URL of the deployment manifest is: " & vbLf & _
                serverDocument1.DeploymentManifestUrl.ToString())
        End If

    Catch ex As System.IO.FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    Catch ex As UnknownCustomizationFileException
        System.Windows.Forms.MessageBox.Show("The specified document has a file " & _
            "extension that is not supported by Visual Studio Tools for Office.")
    Finally
        If Not (serverDocument1 Is Nothing) Then
            serverDocument1.Close()
        End If
    End Try
End Sub
private void CreateServerDocumentFromPath(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            serverDocument1 = new ServerDocument(documentPath);
            MessageBox.Show("The URL of the deployment manifest is: \n" +
                serverDocument1.DeploymentManifestUrl.ToString());
        }
    }
    catch (System.IO.FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    catch (UnknownCustomizationFileException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document has a file " +
            "extension that is not supported by Visual Studio Tools for Office.");
    }
    finally
    {
        if (serverDocument1 != null)
            serverDocument1.Close();
    }
}

継承階層

System.Object
  Microsoft.VisualStudio.Tools.Applications.ServerDocument

スレッド セーフ

この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。

参照

参照

ServerDocument メンバ

Microsoft.VisualStudio.Tools.Applications 名前空間

その他の技術情報

ServerDocument クラスによるサーバー上のドキュメントの管理

Office ソリューションにおけるアプリケーション マニフェストと配置マニフェスト

サーバー上のドキュメント内のデータへのアクセス

方法 : サーバー上のブックにデータを挿入する

方法 : サーバー上のブックからキャッシュされたデータを取得する

方法 : サーバー上のブックでキャッシュされたデータを変更する