Aracılığıyla paylaş


ServerDocument.AddCustomization Yöntem (String, String, Guid, Uri)

Bir özelleştirme, belirtilen belge, derleme adı, çözüm kimliği ve dağıtım listesi kullanarak belirtilen belgeye ekler.

Ad alanı:  Microsoft.VisualStudio.Tools.Applications
Derleme:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll içinde)

Sözdizimi

'Bildirim
Public Shared Sub AddCustomization ( _
    documentPath As String, _
    assemblyName As String, _
    solutionId As Guid, _
    deploymentManifestUrl As Uri _
)
public static void AddCustomization(
    string documentPath,
    string assemblyName,
    Guid solutionId,
    Uri deploymentManifestUrl
)

Parametreler

  • documentPath
    Tür: System.String
    Bir özelleştirme eklemek istediğiniz belgenin tam yolu.
  • assemblyName
    Tür: System.String
    Özelleştirme için derlemenin tam yolu.Yol, yerel dosya sistemine veya bir unc paylaşımında olmalıdır; http konumu belirtemezsiniz.
  • solutionId
    Tür: System.Guid
    Bir GUID, Visual Studio Tools for Office çalışma zamanı modülü kullanır tanımlama çözümü.
  • deploymentManifestUrl
    Tür: System.Uri
    Çözüm dağıtım listesi URL'si.

Özel Durumlar

Exception Koşul
ArgumentNullException

documentPathor assemblyName is nullnull başvuru (Visual Basic\'te Nothing) or empty.

FileNotFoundException

documentPathveya assemblyName var olmayan bir dosyaya başvuruyor.

DocumentAlreadyCustomizedException

Belirtilen belge documentPath zaten özelleştirme.

DocumentNotCustomizedException

Belirtilen belge documentPath bozuk, veya kısıtlı izinleri.

UnknownCustomizationFileException

Belirtilen belge documentPath tarafından desteklenmeyen bir dosya adı uzantısına sahip Visual Studio Tools for Office çalışma zamanı modülü.

Açıklamalar

AddCustomization Yöntemi associates belirtilen özelleştirme belgeyle ekleyerek _AssemblyName ve _AssemblyLocation özel belge özellikleri belge. Bu özellikler belge bir özelleştirme sahiptir ve dağıtım bildirim konumunu tanımlar. Bu yöntem başarılı bir şekilde, bir kullanıcı belirtilen belge bir sonraki açışında çağrıldıktan sonra çalışma zamanı Office çözüm yüklemeyi dener. Özel belge özellikleri hakkında daha fazla bilgi için bkz: Özel Belge Özelliklerine Genel Bakış.

Geçişi için GUID solutionID parametresi belirtilmişse uygulama bildirimi çözümün, bağladığınız belge. Belirtilen aynı GUID geçmesi gereken solutionId özniteliği vstov4:document öğesi uygulama bildirimi. Daha fazla bilgi için bkz:Office Çözümlerinde Uygulama ve Dağıtım Bildirimleri ve <belge> öğe (Office Visual Studio geliştirme).

Özelleştirme yayımlama konumundan iliştiriyorsanız, derleme için doğru dosya adını belirttiğinizden emin olun assemblyName parametresi. Office çözüm yayımladığınızda, yayımlama klasöre kopyalanır derleme .deploy dosya adı uzantısı vardır. Derleme adı WordDocument1.dll ise, örneğin, dosya yayınlama klasöründe derleme WordDocument1.dll.deploy adıdır. Daha fazla bilgi için bkz. Office Çözümleri Yayımlama.

Belirtilen belge özelleştirme beklediği için belge denetim içermiyorsa, AddCustomization yöntemi başarılı olur, ancak derleme açtığında yüklemek başarısız olurbelge.

fileType Parametresi, bir belgeyi Microsoft Office Word ve belge düzeyinde özelleştirmeleri için desteklenen dosya adı uzantısına sahip belirtmeniz gerekirMicrosoft Office Excel. Word xml belgesinde kayıtlı olan bir belgeye bir özelleştirme eklenemiyor (* xml) veya Word 2003 xml belgesi (* xml) dosya formatları. Desteklenen dosya türleri hakkında daha fazla bilgi için bkz: Belge Düzeyi Özelleştirmeleri Mimarisi.

Örnekler

Aşağıdaki kod örneği AddCustomization yöntemine ekleyin bir özelleştirme için belirtilen belge.

Bu örnek aşağıdakileri gerektirir:

  • Bir konsol uygulaması projesi veya başka bir Office dışı projeye.

  • Aşağıdaki derlemelerine başvurular:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.dll (eğer proje .NET Framework 4'i hedefliyorsa).

      ya da

    • Microsoft.Visualstudio.Tools.Applications.ServerDocument.V10.0.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (, proje hedefleri.net Framework 3.5).

Private Sub AddCustomizationUsingAssemblyPath(ByVal documentPath As String, _
    ByVal assemblyName As String, ByVal solutionID As Guid, 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, assemblyName, solutionID, 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 AddCustomizationUsingAssemblyPath(string documentPath, string assemblyName, 
    Guid solutionID, 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, assemblyName, solutionID, 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);
    }
}

.NET Framework Güvenliği

Ayrıca bkz.

Başvuru

ServerDocument Sınıf

AddCustomization Fazla Yük

Microsoft.VisualStudio.Tools.Applications Ad Alanı

Diğer Kaynaklar

Office Çözümlerinde Uygulama ve Dağıtım Bildirimleri

Office Çözümleri Yayımlama