ServerDocument.RemoveCustomization Method
Removes the customization from the document.
Assembly: Microsoft.VisualStudio.Tools.Applications.ServerDocument (in Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)
Parameters
- documentPath
- Type: System.String
The full path of the document from which you want to remove the customization.
| Exception | Condition |
|---|---|
| ArgumentNullException |
The documentPath parameter is null or empty or consists completely of white space characters. |
| FileNotFoundException |
The file specified by documentPath does not exist. |
| IOException |
The file specified by documentPath is read-only, or cannot be accessed. |
| InvalidOperationException |
The file specified by documentPath does not have a customization, or an error occurred while loading the manifest. |
| DocumentCustomizedWithPreviousRuntimeException |
The file specified by documentPath has a customization that was not created with the Visual Studio 2010 Tools for Office Runtime or the Visual Studio Tools for the Microsoft Office system (version 3.0 Runtime). |
This method clears the deployment manifest URL and the cached data manifest, and removes any cached data from the document. For more information, see How to: Remove Managed Code Extensions from Documents.
The following code example uses the RemoveCustomization method to remove the customization from the specified document. The example first calls the GetCustomizationVersion method to determine whether the document has a customization.
This example requires:
-
A console application project or some other non-Office project.
-
References to the following assemblies:
-
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll and Microsoft.VisualStudio.Tools.Applications.Runtime.dll (if the project targets the .NET Framework 4).
or
-
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll and Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (if the project targets the .NET Framework 3.5).
-
-
Imports (for Visual Basic) or using (for C#) statements for Microsoft.VisualStudio.Tools.Applications and Microsoft.VisualStudio.Tools.Applications.Runtime namespaces at the top of your code file.
private static void RemoveAssembly(string documentPath) { int runtimeVersion = 0; try { runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath); // Make sure that this customization was created using the correct runtime. if (runtimeVersion != 3) { MessageBox.Show("This document does not have a Visual Studio Tools for " + "Office customization, or it has a customization that was created with " + "a version of the runtime that is incompatible with this version of the " + "ServerDocument class."); return; } ServerDocument.RemoveCustomization(documentPath); MessageBox.Show("The customization has been removed."); } catch (System.IO.FileNotFoundException) { System.Windows.Forms.MessageBox.Show("The specified document does not exist."); } catch (System.IO.IOException) { System.Windows.Forms.MessageBox.Show("The specified document is read-only."); } 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 (InvalidOperationException ex) { System.Windows.Forms.MessageBox.Show("The customization could not be removed.\n" + ex.Message); } }
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.