次の方法で共有


ServerDocument コンストラクタ (array<Byte[], String) (2007 System)

更新 : 2007 年 11 月

読み込むドキュメントを表すバイト配列およびドキュメントのファイル名拡張子を使用して、ServerDocument クラスの新しいインスタンスを初期化します。

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

構文

'宣言
Public Sub New ( _
    bytes As Byte(), _
    fileType As String _
)
'使用
Dim bytes As Byte()
Dim fileType As String

Dim instance As New ServerDocument(bytes, fileType)
public ServerDocument(
    byte[] bytes,
    string fileType
)

パラメータ

  • bytes
    型 : array<System.Byte[]

    読み込むドキュメントを表すバイト配列。

  • fileType
    型 : System.String

    bytes パラメータに格納されるドキュメントのファイル名の拡張子です。拡張子の前にはピリオド (.) が付きます。たとえば、".xlsx" や ".docx" のようになります。

例外

例外 条件
ArgumentNullException

bytes パラメータが nullnull 参照 (Visual Basic では Nothing) または空です。

または

fileType パラメータは、nullnull 参照 (Visual Basic では Nothing) または空であるか、または空白文字から構成されます。

UnknownCustomizationFileException

fileType パラメータは、Visual Studio Tools for Office ではサポートされないファイル名拡張子を指定します。

DocumentCustomizedWithPreviousRuntimeException

documentPath で指定されたファイルに、以前のバージョンの Visual Studio Tools for Office ランタイムで作成されたカスタマイズが含まれています。

解説

このコンストラクタを使用して、メモリ内に既に存在するドキュメントのキャッシュされたデータや配置マニフェスト情報にアクセスします。このコンストラクタを使用すると、ドキュメントは読み取り/書き込みアクセスで開かれます。

fileType パラメータは、バイト配列に保存されているドキュメントの種類を指定するためにのみ使用されます。fileType の値は、ドキュメント レベルのカスタマイズでサポートされるいずれかのファイルの種類にマップされます。ファイルは開かれません。完全なファイル名 (たとえば、"Workbook1.xlsx" など) を渡すこともできますが、このように操作しても、使用されるのはファイル名の拡張子だけです。サポートされるファイルの種類の詳細については、「ドキュメント レベルのカスタマイズのアーキテクチャ」を参照してください。

このコンストラクタを呼び出した後、ドキュメントのバイト配列にアクセスするには、Document プロパティを使用します。

次のコード例は、ServerDocument(array<Byte[], String) コンストラクタを使用して、.xlsx ファイル名拡張子が設定された Excel ブックを含むバイト配列から新しい ServerDocument を作成します。また、Document プロパティを使用してドキュメントのバイト数を表示します。

この例では、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 CreateServerDocumentFromByteArray(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing
    Dim stream As System.IO.FileStream = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            ' Read the file into a byte array.
            stream = New System.IO.FileStream(documentPath, System.IO.FileMode.Open, _
                System.IO.FileAccess.Read)
            Dim buffer(Fix(stream.Length)) As Byte
            stream.Read(buffer, 0, Fix(buffer.Length))

            ' Display the number of bytes in the document.
            serverDocument1 = New ServerDocument(buffer, "*.xlsx")
            MessageBox.Show("The Document property contains " & _
                serverDocument1.Document.Length.ToString() & " bytes.")
        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
        If Not (stream Is Nothing) Then
            stream.Close()
        End If
    End Try
End Sub
private void CreateServerDocumentFromByteArray(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;
    System.IO.FileStream stream = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            // Read the file into a byte array.
            stream = new System.IO.FileStream(
                documentPath, System.IO.FileMode.Open,
                System.IO.FileAccess.Read);
            byte[] buffer = new byte[(int)stream.Length];
            stream.Read(buffer, 0, (int)buffer.Length);

            // Display the number of bytes in the document.
            serverDocument1 = new ServerDocument(buffer,
                "*.xlsx");
            MessageBox.Show("The Document property contains " +
                serverDocument1.Document.Length.ToString() +
                " bytes.");
        }
    }
    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();
        if (stream != null)
            stream.Close();
    }
}

アクセス許可

  • 直前の呼び出し元に対する完全な信頼。このメンバは、部分的に信頼されているコードから使用することはできません。詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

ServerDocument クラス

ServerDocument メンバ

ServerDocument オーバーロード

Microsoft.VisualStudio.Tools.Applications 名前空間