ServerDocument.AddCustomization Yöntem (String, Uri)
Bir özelleştirme belirtilen derleme adı ve dağıtım bildirimini kullanarak belirli bir 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, _
deploymentManifestUrl As Uri _
)
public static void AddCustomization(
string documentPath,
Uri deploymentManifestUrl
)
Parametreler
- documentPath
Tür: System.String
Özelleştirme iliştirmek istediğiniz belgenin tam yolu.
- deploymentManifestUrl
Tür: System.Uri
Çözüm için dağıtım bildiriminin URL'i.
Özel Durumlar
Exception | Koşul |
---|---|
ArgumentNullException | documentPathor deploymentManifestUrl is nullnull başvuru (Visual Basic'te Nothing) or empty. |
ArgumentException | deploymentManifestUrlmutlak URL belirtmiyor. |
FileNotFoundException | documentPathveya deploymentManifestUrl var olmayan bir dosyaya başvuruyor. |
DocumentAlreadyCustomizedException | Belirtilen belge documentPath zaten bir özelleştirme vardır. |
InvalidManifestException | Tarafından belirtilen dağıtım bildirimini deploymentManifestUrl geçerli dağıtım bildirimini değil. |
DocumentNotCustomizedException | Belirtilen belge documentPath bozuk veya sınırlı izinlere sahip. |
UnknownCustomizationFileException | Belirtilen belge documentPath tarafından desteklenmeyen bir dosya adı uzantısına sahip Office için Visual Studio Araçları çalışma zamanı modülü. |
Notlar
AddCustomization Yöntemi associates belirtilen özelleştirme belgeyle ekleyerek _AssemblyName ve _AssemblyLocation belgeye özel belge özelliklerini.Bu özellikler belge özelleştirmeye sahiptir ve dağıtım bildiriminin konumunu tanımlayın.Bu yöntem başarılı bir şekilde, bir kullanıcı belirtilen belge açıldığında çağrıldıktan sonra Office çözümü yüklemek çalışma zamanı deneyecek.Özel belge özellikleri hakkında daha fazla bilgi için bkz: Özel Belge Özelliklerine Genel Bakış.
Belirtilen belge için belgeyi özelleştirme beklediği denetim içermiyorsa, AddCustomization yöntem başarılı olur, ancak derleme kullanıcı belgeyi açtığında yüklemede başarısız olur.
fileType Parametresi, belge düzeyi özelleştirmeleri için desteklenen bir dosya adı uzantısına sahip bir belge belirtmelisiniz.Bir özelleştirme Word XML belgesi kaydedildiğinde belgeye 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ştirmeler Mimarisi.
Örnekler
Aşağıdaki kod örnek AddCustomization özelleştirme belirli bir belgeye iliştirmek için yöntem.
Bu örnek aşağıdakileri gerektirir:
Konsol uygulama projesi veya başka bir Office dışı proje.
Aşağıdaki derlemelere başvurular:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.dll (durumunda proje hedefleri .NET Framework 4 veya .NET Framework 4.5).
veya
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll ve Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (proje .NET Framework 3.5 hedefliyorsa).
Imports(Visual Basic için) veya using için (C#) deyimleri için Microsoft.VisualStudio.Tools.Applications ve Microsoft.VisualStudio.Tools.Applications.Runtime kod dosyanın üst ad.
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);
}
}
.NET Framework Güvenliği
- Anında arayanlar için tam güven. Bu üye kısmen güvenilen kodla kullanılamaz. Daha fazla bilgi için bkz. Kısmen Güvenilen Koddan Kitaplıkları Kullanma.