Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > How can I remove the customization from a VSTO document?
Ask a questionAsk a question
 

LockedHow can I remove the customization from a VSTO document?

Locked

  • Sunday, February 08, 2009 12:45 PMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    How can I remove the customization from a VSTO document?



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Answers

  • Sunday, February 08, 2009 12:46 PMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Visual Studio Tools for Office provides a class named ServerDocument which can access the cached data and application manifest in a customized document. In Office 2003 projects, this class is implemented by VSTO 2005 SE Runtime and included in the namespace Microsoft.VisualStudio.Tools.Applications.Runtime, while it is implemented by VSTO 3.0 Runtime and included in the Microsoft.VisualStudio.Tools.Applications namespace for Office 2007 projects.

    Since the implementations of VSTO 2005 SE Runtime and VSTO Runtime 3.0 are different, the usages of the two ServerDocument classes are also not consistent. However, for the RemoveCustomization() method, they are identical and only requires a string type parameter which points to the full path of the document which you want to remove the customization. Please refer to the below codes to achieve these results:

    private static void Remove(string fileName)

    {

        if (ServerDocument.IsCustomized(fileName))

        {

            ServerDocument.RemoveCustomization(fileName);

            MessageBox.Show("The customization has been removed.");

        }

        else

        {

            MessageBox.Show("The specified document is not " +

                "customized.");

        }

    }

    (Related forum thread http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/a0cdb75a-b143-47f4-909d-5af529ec704f/ )



    For more FAQ about Visual Studio Tools for Office, please see Visual Studio Tools for Office FAQ



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

All Replies

  • Sunday, February 08, 2009 12:46 PMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Visual Studio Tools for Office provides a class named ServerDocument which can access the cached data and application manifest in a customized document. In Office 2003 projects, this class is implemented by VSTO 2005 SE Runtime and included in the namespace Microsoft.VisualStudio.Tools.Applications.Runtime, while it is implemented by VSTO 3.0 Runtime and included in the Microsoft.VisualStudio.Tools.Applications namespace for Office 2007 projects.

    Since the implementations of VSTO 2005 SE Runtime and VSTO Runtime 3.0 are different, the usages of the two ServerDocument classes are also not consistent. However, for the RemoveCustomization() method, they are identical and only requires a string type parameter which points to the full path of the document which you want to remove the customization. Please refer to the below codes to achieve these results:

    private static void Remove(string fileName)

    {

        if (ServerDocument.IsCustomized(fileName))

        {

            ServerDocument.RemoveCustomization(fileName);

            MessageBox.Show("The customization has been removed.");

        }

        else

        {

            MessageBox.Show("The specified document is not " +

                "customized.");

        }

    }

    (Related forum thread http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/a0cdb75a-b143-47f4-909d-5af529ec704f/ )



    For more FAQ about Visual Studio Tools for Office, please see Visual Studio Tools for Office FAQ



    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Wednesday, April 01, 2009 12:07 PMJi.ZhouMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Add VB version codes,

    Private Shared Sub Remove(ByVal fileName As String)
        If(ServerDocument.IsCustomized(fileName)) Then
            ServerDocument.RemoveCustomization(fileName)
            MessageBox.Show("The customization has been removed.")
        Else
            MessageBox.Show("The specified document is not " + "customized.")
        End If
    End Sub

    We have published a VSTO FAQ recently, you can view them from the entry thread http://social.msdn.microsoft.com/Forums/en/vsto/thread/31b1ffbf-117b-4e8f-ad38-71614437df59. If you have any feedbacks or suggestions on this FAQ, please feel free to write us emails to colbertz@microsoft.com.