Metoda ServerDocument.AddCustomization — (String, Uri)

Dołącza dostosowań do określonego dokumentu przy użyciu określonego zestawu manifestu nazwy i wdrażania.

Przestrzeń nazw:  Microsoft.VisualStudio.Tools.Applications
Zestaw:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (w Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Składnia

'Deklaracja
Public Shared Sub AddCustomization ( _
    documentPath As String, _
    deploymentManifestUrl As Uri _
)
public static void AddCustomization(
    string documentPath,
    Uri deploymentManifestUrl
)

Parametry

  • documentPath
    Typ: System.String
    Pełna ścieżka dokumentu, do którego chcesz dołączyć pliku dostosowań.
  • deploymentManifestUrl
    Typ: System.Uri
    Adres URL manifestu wdrażania rozwiązania.

Wyjątki

Wyjątek Warunek
ArgumentNullException

documentPathor deploymentManifestUrl is nullodwołanie o wartości null (Nothing w języku Visual Basic) or empty.

ArgumentException

deploymentManifestUrlnie określa bezwzględny adres URL.

FileNotFoundException

documentPathlub deploymentManifestUrl odwołuje się do pliku, który nie istnieje.

DocumentAlreadyCustomizedException

Dokument określony przez documentPath ma już pliku dostosowań.

InvalidManifestException

Manifest wdrażania określony przez deploymentManifestUrl nie jest prawidłowy manifest wdrażania.

DocumentNotCustomizedException

Dokument określony przez documentPath jest uszkodzony lub ma ograniczone uprawnienia.

UnknownCustomizationFileException

Dokument określony przez documentPath ma rozszerzenie nazwy pliku, który nie jest obsługiwany przez Visual Studio 2010 Tools for Office Runtime.

Uwagi

AddCustomization Metoda kojarzy z dokumentem dostosowania określonego przez dodanie _AssemblyName i _AssemblyLocation niestandardowe właściwości dokumentu w dokumencie.Te właściwości identyfikacji, że dokument ma dostosowywania i określ lokalizację manifestu wdrażania.Po tym wywoływana jest metoda pomyślnie, przy następnym otwarciu dokumentu określonego środowiska wykonawczego spróbuje zainstalować rozwiązania pakietu Office.Aby uzyskać więcej informacji o właściwościach niestandardowych dokumentu, zobacz Niestandardowe właściwości dokumentu ― Omówienie.

Jeśli określony dokument nie zawiera formant, który dostosowanie oczekuje, że dokument musi mieć, AddCustomization metoda zostanie wykonana pomyślnie, ale zestaw nie będzie można załadować, gdy użytkownik otworzy dokument.

fileType Parametr należy określić dokumentu, który ma rozszerzenie nazwy pliku obsługiwaną dla dostosowania poziomu dokumentu.Nie można dołączyć pliku dostosowań do dokumentu, który jest zapisany w dokumencie XML programu Word (* xml) lub dokument XML programu Word 2003 (* xml) formatów plików.Aby uzyskać więcej informacji na temat obsługiwanych typów plików, zobacz Architektura dostosowywania na poziomie dokumentu.

Przykłady

Następujący kod w przykładzie wykorzystano AddCustomization metoda do dołączenia pliku dostosowań do określonego dokumentu.

W tym przykładzie wymaga:

  • Projekt aplikacji konsoli lub innych projektów nienależących do pakietu Office.

  • Odwołania do następujących zestawów:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jeśli cele projektu .NET Framework 4 lub .NET Framework 4.5).

      lub

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (Jeśli projekt jest przeznaczony dla.NET Framework 3.5).

  • Imports(dla Visual Basic) lub using (w przypadku C#) oświadczenia dla Microsoft.VisualStudio.Tools.Applications i Microsoft.VisualStudio.Tools.Applications.Runtime obszarów nazw u góry pliku kodu.

Private Sub AddCustomizationUsingDocumentPath(ByVal documentPath As String, _
    ByVal deployManifestPath As String)
    Dim runtimeVersion As Integer = 0

    Try
        ' Make sure that this document does not yet have any Visual Studio Tools 
        ' for Office customizations.
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 0 Then
            Dim deploymentManifestUri As New Uri(deployManifestPath)
            ServerDocument.AddCustomization(documentPath, deploymentManifestUri)
            MessageBox.Show("The document was successfully customized.")
        Else
            System.Windows.Forms.MessageBox.Show("The document is already customized.")
        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.")
    Catch ex As DocumentNotCustomizedException
        System.Windows.Forms.MessageBox.Show("The document could not be customized." & _
        vbLf & ex.Message)
    End Try
End Sub
private void AddCustomizationUsingDocumentPath(string documentPath, string deployManifestPath)
{
    int runtimeVersion = 0;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);

        // Make sure that this document does not yet have any Visual Studio Tools 
        // for Office customizations.
        if (runtimeVersion == 0)
        {
            Uri deploymentManifestUri = new Uri(deployManifestPath);
            ServerDocument.AddCustomization(documentPath, deploymentManifestUri);
            MessageBox.Show("The document was successfully customized.");
        }
        else
        {
            System.Windows.Forms.MessageBox.Show("The document is already customized.");
        }
    }
    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.");
    }
    catch (DocumentNotCustomizedException ex)
    {
        System.Windows.Forms.MessageBox.Show("The document could not be customized.\n" +
            ex.Message);
    }
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

ServerDocument Klasa

Przeciążenie AddCustomization

Przestrzeń nazw Microsoft.VisualStudio.Tools.Applications