Bagikan melalui


ServerDocument Konstruktor

Definisi

Overload

ServerDocument(String)

Menginisialisasi instans ServerDocument baru kelas menggunakan jalur lengkap dokumen yang akan dimuat.

ServerDocument(Byte[], String)

Menginisialisasi instans ServerDocument baru kelas menggunakan array byte yang mewakili dokumen yang akan dimuat dan ekstensi nama file dokumen.

ServerDocument(Stream, String)

Menginisialisasi instans ServerDocument baru kelas menggunakan aliran yang mewakili dokumen yang akan dimuat dan ekstensi nama file dokumen.

ServerDocument(String, FileAccess)

Menginisialisasi instans ServerDocument baru kelas menggunakan jalur lengkap dokumen yang akan dimuat dan nilai yang menunjukkan akses file untuk dokumen.

ServerDocument(String)

Menginisialisasi instans ServerDocument baru kelas menggunakan jalur lengkap dokumen yang akan dimuat.

public:
 ServerDocument(System::String ^ documentPath);
public ServerDocument (string documentPath);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : string -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (documentPath As String)

Parameter

documentPath
String

Jalur lengkap dokumen yang akan dimuat.

Pengecualian

Parameternya documentPath adalah null atau kosong atau sepenuhnya terdiri dari karakter spasi kosong.

File yang ditentukan oleh documentPath tidak ada.

File yang ditentukan dengan documentPath memiliki kustomisasi yang tidak dibuat dengan Alat Visual Studio 2010 untuk Office Runtime atau Alat Visual Studio untuk sistem Microsoft Office (Runtime versi 3.0).

File yang ditentukan dengan documentPath memiliki ekstensi nama file yang tidak didukung oleh runtime Visual Studio Tools for Office.

Contoh

Contoh kode berikut menggunakan ServerDocument(String) konstruktor untuk membuat baru ServerDocument yang memuat dokumen tertentu. Contoh kemudian menampilkan URL manifes penyebaran untuk kustomisasi yang dilampirkan ke dokumen.

Contoh ini membutuhkan:

  • Proyek aplikasi konsol atau beberapa proyek non-Office lainnya.

  • Referensi ke rakitan berikut:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll dan Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jika proyek menargetkan .NET Framework 4 atau .NET Framework 4,5).

      atau

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll dan Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (jika proyek menargetkan .NET Framework 3.5).

  • Imports (untuk pernyataan Visual Basic) atau using (untuk C#) untuk Microsoft.VisualStudio.Tools.Applications namespace layanan dan Microsoft.VisualStudio.Tools.Applications.Runtime di bagian atas file kode Anda.

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();
    }
}
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

Keterangan

Gunakan konstruktor ini untuk mengakses data yang di-cache atau informasi manifes penyebaran dalam dokumen yang ada di disk. Saat Anda menggunakan konstruktor ini, dokumen yang ditentukan dibuka dengan akses baca/tulis.

Berlaku untuk

ServerDocument(Byte[], String)

Menginisialisasi instans ServerDocument baru kelas menggunakan array byte yang mewakili dokumen yang akan dimuat dan ekstensi nama file dokumen.

public:
 ServerDocument(cli::array <System::Byte> ^ bytes, System::String ^ fileType);
public ServerDocument (byte[] bytes, string fileType);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : byte[] * string -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (bytes As Byte(), fileType As String)

Parameter

bytes
Byte[]

Array byte yang mewakili dokumen yang akan dimuat.

fileType
String

Ekstensi nama file dokumen yang disimpan dalam bytes parameter, didahului oleh titik (.) —misalnya, ".xlsx" atau ".docx".

Pengecualian

Parameternya bytes adalah null atau kosong.-atau-Parameternya fileType adalah null atau kosong atau sepenuhnya terdiri dari karakter spasi putih.

Parameter fileType menentukan ekstensi nama file yang tidak didukung oleh Visual Studio Tools untuk runtime Office.

File yang ditentukan dengan documentPath memiliki kustomisasi yang tidak dibuat dengan Alat Visual Studio 2010 untuk Office Runtime atau Alat Visual Studio untuk sistem Microsoft Office (Runtime versi 3.0).

Contoh

Contoh kode berikut menggunakan [Konstruktor ServerDocument (Byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument.%23ctor%28System.Byte%5B%5D%2CS> konstruktor [ServerDocument Constructor) baru (Byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument> dari array byte yang berisi buku kerja Excel dengan ekstensi nama file .xlsx. Contohnya kemudian menggunakan properti [ServerDocument Constructor (Byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument.Document%2A> untuk menampilkan jumlah byte dalam dokumen.

Contoh ini membutuhkan:

  • Proyek aplikasi konsol atau beberapa proyek non-Office lainnya.

  • Referensi ke rakitan berikut:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll dan Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jika proyek menargetkan .NET Framework 4 atau .NET Framework 4,5).

      atau

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll dan Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (jika proyek menargetkan .NET Framework 3.5).

  • Imports (untuk Visual Basic) atau using (untuk C#) pernyataan untuk [ServerDocument Constructor (Byte<xref:Microsoft.VisualStudio.Tools.Applications?displayProperty=fullName> dan [ServerDocument Constructor (Byte<xref:Microsoft.VisualStudio.Tools.Applications.Runtime?displayProperty=fullName> namespaces di bagian atas file kode Anda.

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();
    }
}
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

Keterangan

Gunakan konstruktor ini untuk mengakses data yang di-cache atau informasi manifes penyebaran dalam dokumen yang sudah ada dalam memori. Saat Anda menggunakan konstruktor ini, dokumen dibuka dengan akses baca/tulis.

Parameter fileType hanya digunakan untuk menentukan jenis dokumen yang disimpan dalam array byte. Nilai fileType dipetakan ke salah satu jenis file yang didukung untuk penyesuaian tingkat dokumen. Tidak ada upaya yang dilakukan untuk membuka file. Anda dapat secara opsional meneruskan nama file lengkap (misalnya, "Workbook1.xlsx"), tetapi jika Anda melakukan ini, hanya ekstensi nama file yang digunakan. Untuk informasi selengkapnya tentang jenis file yang didukung, lihat Arsitektur kustomisasi Document-Level.

Untuk mengakses array byte untuk dokumen setelah memanggil konstruktor ini, gunakan properti [ServerDocument Constructor (Byte<xref:Microsoft.VisualStudio.Tools.Applications.ServerDocument.Document%2A> .

Berlaku untuk

ServerDocument(Stream, String)

Menginisialisasi instans ServerDocument baru kelas menggunakan aliran yang mewakili dokumen yang akan dimuat dan ekstensi nama file dokumen.

public:
 ServerDocument(System::IO::Stream ^ stream, System::String ^ fileType);
public ServerDocument (System.IO.Stream stream, string fileType);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : System.IO.Stream * string -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (stream As Stream, fileType As String)

Parameter

stream
Stream

Aliran yang mewakili dokumen yang akan dimuat.

fileType
String

Ekstensi nama file dokumen yang disimpan dalam bytes parameter, didahului oleh titik (.) —misalnya, ".xlsx" atau ".docx".

Pengecualian

Parameternya stream adalah null atau kosong.-atau-Parameternya fileType adalah null atau kosong atau sepenuhnya terdiri dari karakter spasi putih.

Parameter stream memiliki panjang nol atau posisinya saat ini berada di ujung aliran.

Parameter fileType menentukan ekstensi nama file yang tidak didukung oleh Visual Studio Tools untuk runtime Office.

File yang ditentukan dengan documentPath memiliki kustomisasi yang tidak dibuat dengan Alat Visual Studio 2010 untuk Office Runtime atau Alat Visual Studio untuk sistem Microsoft Office (Runtime versi 3.0).

Contoh

Contoh kode berikut menggunakan ServerDocument(Stream, String) konstruktor untuk membuat baru ServerDocument dari yang FileStream berisi buku kerja Excel dengan ekstensi nama file .xlsx. Kode kemudian menampilkan URL manifes penyebaran untuk kustomisasi yang dilampirkan ke dokumen.

Contoh ini membutuhkan:

  • Proyek aplikasi konsol atau beberapa proyek non-Office lainnya.

  • Referensi ke rakitan berikut:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll dan Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jika proyek menargetkan .NET Framework 4 atau .NET Framework 4,5).

      atau

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll dan Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (jika proyek menargetkan .NET Framework 3.5).

  • Imports (untuk pernyataan Visual Basic) atau using (untuk C#) untuk Microsoft.VisualStudio.Tools.Applications namespace layanan dan Microsoft.VisualStudio.Tools.Applications.Runtime di bagian atas file kode Anda.

private void CreateServerDocumentFromStream(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;
    System.IO.FileStream stream = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            stream = new System.IO.FileStream(
                documentPath, System.IO.FileMode.Open);
            serverDocument1 = new ServerDocument(stream,
                "*.xlsx");
            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();
        if (stream != null)
            stream.Close();
    }
}
Private Sub CreateServerDocumentFromStream(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
            stream = New System.IO.FileStream(documentPath, System.IO.FileMode.Open)
            serverDocument1 = New ServerDocument(stream, "*.xlsx")
            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
        If Not (stream Is Nothing) Then
            stream.Close()
        End If
    End Try
End Sub

Keterangan

Gunakan konstruktor ini untuk mengakses data yang di-cache atau informasi manifes penyebaran dalam dokumen yang sudah ada dalam memori. Saat Anda menggunakan konstruktor ini, dokumen dibuka dengan akses baca/tulis.

Parameter fileType hanya digunakan untuk menentukan jenis dokumen yang disimpan dalam array byte. Nilai fileType dipetakan ke salah satu jenis file yang didukung untuk penyesuaian tingkat dokumen. Tidak ada upaya yang dilakukan untuk membuka file. Anda dapat secara opsional meneruskan nama file lengkap (misalnya, "Workbook1.xlsx"), tetapi jika Anda melakukan ini, hanya ekstensi nama file yang digunakan. Untuk informasi selengkapnya tentang jenis file yang didukung, lihat Arsitektur kustomisasi Document-Level.

Untuk mengakses array byte untuk dokumen setelah memanggil konstruktor ini, gunakan Document properti .

Berlaku untuk

ServerDocument(String, FileAccess)

Menginisialisasi instans ServerDocument baru kelas menggunakan jalur lengkap dokumen yang akan dimuat dan nilai yang menunjukkan akses file untuk dokumen.

public:
 ServerDocument(System::String ^ documentPath, System::IO::FileAccess access);
public ServerDocument (string documentPath, System.IO.FileAccess access);
new Microsoft.VisualStudio.Tools.Applications.ServerDocument : string * System.IO.FileAccess -> Microsoft.VisualStudio.Tools.Applications.ServerDocument
Public Sub New (documentPath As String, access As FileAccess)

Parameter

documentPath
String

Jalur lengkap dokumen yang akan dimuat.

access
FileAccess

Nilai yang menunjukkan akses file untuk dokumen.

Pengecualian

Parameternya documentPath adalah null atau kosong atau sepenuhnya terdiri dari karakter spasi kosong.

Nilainya access adalah System.IO.FileAccess.Write.

File yang ditentukan oleh documentPath tidak ada.

File yang ditentukan oleh documentPath parameter tidak memiliki kustomisasi, dan nilainya access adalah System.IO.FileAccess.Read.

File yang ditentukan dengan documentPath memiliki kustomisasi yang tidak dibuat dengan Alat Visual Studio 2010 untuk Office Runtime atau Alat Visual Studio untuk sistem Microsoft Office (Runtime versi 3.0).

File yang ditentukan dengan documentPath memiliki ekstensi nama file yang tidak didukung oleh runtime Visual Studio Tools for Office.

Contoh

Contoh kode berikut menggunakan ServerDocument(String, FileAccess) konstruktor untuk membuat baru ServerDocument yang memuat dokumen tertentu dengan akses baca-saja. Kode kemudian menampilkan URL manifes penyebaran untuk kustomisasi yang dilampirkan ke dokumen.

Contoh ini membutuhkan:

  • Proyek aplikasi konsol atau beberapa proyek non-Office lainnya.

  • Referensi ke rakitan berikut:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll dan Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jika proyek menargetkan .NET Framework 4 atau .NET Framework 4,5).

      atau

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll dan Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (jika proyek menargetkan .NET Framework 3.5).

  • Imports (untuk pernyataan Visual Basic) atau using (untuk C#) untuk Microsoft.VisualStudio.Tools.Applications namespace layanan dan Microsoft.VisualStudio.Tools.Applications.Runtime di bagian atas file kode Anda.

private void CreateServerDocumentReadOnly(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            serverDocument1 = new ServerDocument(documentPath,
                System.IO.FileAccess.Read);
            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 (DocumentNotCustomizedException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not " +
            "have a customization.");
    }
    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();
    }
}
Private Sub CreateServerDocumentReadOnly(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, System.IO.FileAccess.Read)
            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 DocumentNotCustomizedException
        System.Windows.Forms.MessageBox.Show("The specified document does not " & _
            "have a customization.")
    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

Keterangan

Gunakan konstruktor ini untuk mengakses data yang di-cache atau informasi manifes penyebaran dalam dokumen yang ada di disk jika Anda ingin membuka dokumen dengan akses baca-saja atau tulis-saja. Secara default, konstruktor lain ServerDocument membuka dokumen dengan akses baca/tulis.

Berlaku untuk