Steve 5656565656

Hello,

I have a Word 2003 document with VSTO customization. I want to be able to save this document with VSTO customization to a separate folder where the associated VSTO dll does not exist. When opening this newly saved document, I receive the 'Customization assembly could not be found..." message. I need to be able to strip away the VSTO customization from this document so the document is just a plain old Word document and not a VSTO Word document. Does anyone know how to do this

Steve P



Re: Visual Studio Tools for Office Detaching VSTO customization

McLean Schofield - MSFT

There are several different ways to do this by using APIs included with VSTO. For more information, see the topic "How to: Remove Managed Code Extensions from Documents" (http://msdn2.microsoft.com/en-us/library/8fza57cs(VS.80).aspx).

I hope this helps,

McLean Schofield






Re: Visual Studio Tools for Office Detaching VSTO customization

Steve 5656565656

Thank you for the reply. I implemented the code from the link but now I get a

"The supplied application manifest is not valid." error message. I was reading from other newsgroups regarding this issue and was told that there are two variables that i need to clear to permanently strip anything associated with VSTO from a document. Does anyone know what these two variables are Is there another way to entirely clear the VSTO.

Right now, I have created a toolbar button to allow the user to save the VSTO document to their hard drive, so they can email to someone else, but when their email recipient opens the Word document, they get the "manifest is not valid" error message. I essentially need to convert the VSTO document to a non-VSTO document.





Re: Visual Studio Tools for Office Detaching VSTO customization

McLean Schofield - MSFT

The custom document properties you heard about are _AssemblyName and _AssemblyLocation. These properties identify that the document has a VSTO customization associated with it. For more information, see http://msdn2.microsoft.com/en-us/library/ds87aeyf(VS.80).aspx.

While it is possible to disassociate the VSTO customization from the document by removing these custom document properties, this isn't generally recommended, because artifacts of the VSTO customization (namely, the data cache and the runtime storage control) will remain in the document itself. I'm curious about the "The supplied application manifest is not valid." message you received. Which of the two procedures in the topic http://msdn2.microsoft.com/en-us/library/8fza57cs(VS.80).aspx (that is, calling one of the RemoveCustomization methods, or calling ServerDocument.AppManifest.Clear) did you try that resulted in this error

McLean Schofield






Re: Visual Studio Tools for Office Detaching VSTO customization

Steve 5656565656

Thank you for the reply.

The code I am calling is this:

ServerDocument sd = new ServerDocument(strLoc);

sd.AppManifest.Clear();

sd.Save();

if (sd != null)

{

sd.Close();

}

I do not have any cached data for customizations. Whenever I did call

if (ServerDocument.IsCustomized(strLoc))

{

ServerDocument.RemoveCustomization(strLoc);

}

the code would never reach the line for Removing the documentation.

I would also like to point out that the above code did not cause the 'invalid manifest' error. Here are the steps I took to cause the error:

1. Run the code in a C# console program to clear the manifest.

2. Open the document with the cleared manifest by double-clicking on it from explorer. This would then cause the error.





Re: Visual Studio Tools for Office Detaching VSTO customization

Steve 5656565656

HEllo,

I have found the _AssemblyName and _Assembly location in the File->Properties and the custom tab and was able to delete thse two custom properties. Howver, I need to be able to do this programatically without the user having to delete these two custom properties. Is there a way to do this using VSTO

Any help will be appreciated.

Steve





Re: Visual Studio Tools for Office Detaching VSTO customization

McLean Schofield - MSFT

The ServerDocument.AppManifest.Clear option is to be used only if the document or workbook contains cached data that you want to keep around in the document. In your case, you should instead just use ServerDocument.RemoveCustomization.

if (ServerDocument.IsCustomized(strLoc))

{

ServerDocument.RemoveCustomization(strLoc);

}

I believe that the above code didn't work because you tried calling it on the same document on which you already tried calling ServerDocument.AppManifest.Clear (this caused IsCustomized to return false). Can you please retry the above code on the customized document without first calling ServerDocument.AppManifest.Clear I just tried using it on a customized document, and it worked as expected.

ServerDocument.RemoveCustomization (or ThisWorkbook.RemoveCustomization and ThisDocument.RemoveCustomization, if you want to perform this task in the VSTO assembly itself) is the primary API for automating this task.

I hope this helps,

McLean Schofield






Re: Visual Studio Tools for Office Detaching VSTO customization

Steve 5656565656

Thank you for the reply,

Unfortunately, calling:

if (ServerDocument.IsCustomized(strLoc))

{

ServerDocument.RemoveCustomization(strLoc);

}

didn't work even when I don't clear the manifest. The code never even reaches the RemoveCustomization method. When I force the debugger to run the RemoveCustomization method, I get a 'Lock violation on <strLoc>' exception. I don't want to call any RemoveCustomization methods from within VSTO itselt. I just want to remove the customization from a doc file that is saved to the user's hard drive. I could always send a sample document if you are willing to look at it.

Steve





Re: Visual Studio Tools for Office Detaching VSTO customization

McLean Schofield - MSFT

When you say that the code never reaches RemoveCustomization, is this because IsCustomized returns false If so, that means that the document specified by 'strLoc' doesn't have a VSTO customization associated with it.

The "Lock violation..." message sounds like the document that is specified by your 'strLoc' parameter is open when you run this code. The document must be closed in order to use the ServerDocument.RemoveCustomization method. Can you confirm whether the document is closed when you run the code






Re: Visual Studio Tools for Office Detaching VSTO customization

Steve 5656565656

Hello,

The code never reaches the RemoveCustomization line of code because the IsCustomized property always returns false.

When running this code, I am sure that the document is closed before I even run the code to remove the customization.

Steve





Re: Visual Studio Tools for Office Detaching VSTO customization

McLean Schofield - MSFT

Hm, I'm starting to run out of ideas here. If IsCustomized is returning false, but you are sure that the specified document does in fact still have a customization (that is, if you open the document directly, then the customization still runs), then something strange is going on. Do you have repro projects (both a VSTO project for the document and the project that contains your ServerDocument code) that you could send to me at mclean.schofield@microsoft.com Alternatively, you can try to include the relevant source code from both projects in this thread.






Re: Visual Studio Tools for Office Detaching VSTO customization

Steve 5656565656

Hello,

I have finally resolved my issue. I was clearing the manifest to a document that had no customizatrion in the first place and that method call to clear the manifest seemed to add customization to the file as a result. Here are my observations:

1. Save a Word doc with a manifest and customization.

2. Observe the custom document properties: _AssemblyName, _AsemblyLocation, and SolutionID are present

3.. Remove the customization.

4. Observe the custom document properties: SolutionID is the only custom property present.

5. Call the clear manifest method.

6. Observe the custom document properties: _AssemblyName, _AsemblyLocation, and SolutionID are present

You will note that step 5 re-added these customization variables, _AssemblyName and _AssemblyLocation when clearing the manifest. I don't know if this is intentional for VSTO or if its an error for VSTO.

Thank you McLean for your help. i am very grateful.

Steve P