Laurent Kempé

Hi

I created a solution for authors to publish content on a website I created based on Word 2003 templates and VSTO 2005.

You might download it here: http://www.codeplex.com/THBAuthoring

Now I try to have it running on Word 2007 and get the following error when a user click on the save button or when I do in code document.Save:

This action is not valid outside of a block-level XML

Looking at the stack trace I have seen that it happens in Microsoft.Office.Interop.Word.DocumentClass.Save(), saying object reference not set to an instance of an object.

I would appreciate any help.

Thanks




Re: Visual Studio Tools for Office Word 2003 template document running exception "This action is not valid outside of a block-level XML" when used in Word 2007

Laurent Kempe

Hi

Using a Word 2003 template document solution on Word 2007 i have the following exception when I am saving the document:

This action is not valid outside of a block-level XML

Looking at the stack trace I have seen that it happens in Microsoft.Office.Interop.Word.DocumentClass.Save(), saying object reference not set to an instance of an object.

I would appreciate any help.

Thanks






Re: Visual Studio Tools for Office Word 2003 template document running exception "This action is not valid outside of a block-level XML" when used in Word 2007

Christin-MSFT

The VSTO Second Edition Runtime solves many problems associated with running a Word 2003 doc project in Word 2007. Try loading the Second Edition Runtime and see if you still get the same error.




Re: Visual Studio Tools for Office Word 2003 template document running exception "This action is not valid outside of a block-level XML" when used in Word 2007

Laurent Kempe

Hi

Do you mean by loading that I need to install VSTO 2005 SE Because I have it installed.

Regards






Re: Visual Studio Tools for Office Word 2003 template document running exception "This action is not valid outside of a block-level XML" when used in Word 2007

Christin-MSFT

Yes, when you installed VSTO 2005 SE it also installed SE runtime. My next troubleshooting question is: do you have Word 2003 and Word 2007 installed on the same computer It sounds like you do if you're creating a Word 2003 template document project. We explicitly warn against side-by-side installation in the VSTO 2005 SE documentation. If that is the case, then I suggest removing Office 2007 from your development machine and then set set up another machine (or a Virtual PC, or a dual boot) for testing on Word 2007. You can use the easiest form of deployment by simply using the Publish to a shared network location.






Re: Visual Studio Tools for Office Word 2003 template document running exception "This action is not valid outside of a block-level XML" when used in Word 2007

Laurent Kempe

Yeah I have side by side because it was the only way to continue to develop and test. But I have also another pc with only Office 2007 on it and I get the same exact error.

Btw, my project is on CodePlex: http://www.codeplex.com/thbauthoring, if you might have time to look at it, you might find the issue.

Regards,
Laurent






Re: Visual Studio Tools for Office Word 2003 template document running exception "This action is not valid outside of a block-level XML" when used in Word 2007

Laurent Kempe

I was able to track down the source code part that is causing the issue. In the event handler ThisDocument_New I would like to insert XML.

To do that I do:

Content.Text = "";

Content.XMLParentNode.WordOpenXML

object Start = null, End = null;

Range(ref Start, ref End).InsertXML(Settings.Default.Template, ref Start);

If I remove this 4 lines of code than I don't get anymore this exception "This action is not valid outside of a block-level XML" and my application is working.

Did I miss something on the way to insert xml in the document

Thanks for the help.






Re: Visual Studio Tools for Office Word 2003 template document running exception "This action is not valid outside of a block-level XML" when used in Word 2007

Laurent Kempe

Ok I found the way that is working at the end:

object Start = null, End = null;

Range documentRange = this.Range(ref Start, ref End);

object transform = System.Type.Missing;

documentRange.InsertXML(Settings.Default.Template, ref transform);

Great !!!!






Re: Visual Studio Tools for Office Word 2003 template document running exception "This action is not valid outside of a block-level XML" when used in Word 2007

Laurent Kempe

And the real code that caused the issue is only this line:

Content.Text = "";

Smile