Sdílet prostřednictvím


ServerDocument – konstruktor (Stream, String)

Inicializuje novou instanci ServerDocument proudu, který představuje dokument načíst pomocí třídy a příponu názvu souboru dokumentu.

Obor názvů:  Microsoft.VisualStudio.Tools.Applications
Sestavení:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (v Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Syntaxe

'Deklarace
Public Sub New ( _
    stream As Stream, _
    fileType As String _
)
public ServerDocument(
    Stream stream,
    string fileType
)

Parametry

  • fileType
    Typ: System.String
    Přípona názvu souboru uloženého v dokumentu bytes parametr předchází tečka (.)– například "XLSX" nebo ".docx".

Výjimky

Výjimka Podmínka
ArgumentNullException

stream Je parametr nullodkaz Null (Nothing v jazyce Visual Basic) nebo prázdná.

-nebo-

fileType Je parametr nullodkaz Null (Nothing v jazyce Visual Basic) nebo prázdné nebo je celá tvořena bílých znaků.

ArgumentException

stream Parametr má nulovou délku nebo aktuální pozice na konec datového proudu.

UnknownCustomizationFileException

fileType Parametr určuje příponu souboru, která není podporována Visual Studio Tools for Office runtime.

DocumentCustomizedWithPreviousRuntimeException

Určený soubor documentPath má vlastní nastavení, který byl vytvořen pomocí Visual Studio 2010 Tools for Office Runtime nebo Visual Studio Tools pro systém Microsoft Office (verze 3.0 Runtime).

Poznámky

Použijte tento konstruktor přístup dat nebo nasazení manifestu informace v mezipaměti v dokumentu, který je již v paměti. Při použití tohoto konstruktoru dokument otevřít s přístupem pro čtení i zápis.

fileType Parametr se používá pouze k určení typu dokumentu uloženy v byte array. Hodnota fileType je mapován na jeden z typů souborů podporované pro úpravy úrovni dokumentu. Bez pokusu otevřít soubor. Můžete volitelně předáte název souboru (například "Workbook1.xlsx"), ale pokud to uděláte, je použit pouze příponu názvu souboru. Další informace o typech souborů podporovaných Architecture of Document-Level Customizations.

Po volání konstruktoru tento přístup bajtové pole dokumentu, Document vlastnost.

Příklady

Následující kód například použití ServerDocument(Stream, String) konstruktor pro vytvoření nového ServerDocument z FileStream obsahující sešit aplikace Excel s XLSX soubor název rozšíření. Kód poté zobrazí adresu URL manifestu nasazení vlastního nastavení, který je připojen k dokumentu.

Tento příklad vyžaduje:

  • Projekt aplikace konzoly nebo některé jiné-Office project.

  • Odkazy na následující sestavení:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.dll (pokud cíle projektu .NET Framework 4).

      nebo

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (pokud cíle projektu.NET Framework 3.5).

  • Imports(pro Visual Basic) nebo using (pro C#) pro příkazy Microsoft.VisualStudio.Tools.Applications a Microsoft.VisualStudio.Tools.Applications.Runtime obory názvů v horní části souboru kódu.

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

Zabezpečení rozhraní .NET Framework

Viz také

Odkaz

ServerDocument Třída

ServerDocument – přetížení

Microsoft.VisualStudio.Tools.Applications – obor názvů