View Full Version : Re: Error saving Word document as XML


techie
02-20-2006, 09:28 PM
"Cindy M -WordMVP-" <C.Meister-C@hispeed.ch> wrote in message
news:VA.0000ba2f.00a6bfce@speedy...
> Hi Techie,
>
> > The program involves running a validation macro after which the file is
> > saved as an xml file. The error only seems to happen for certain
documents.
> > The documents look fine to me.
> >
> > Any idea why a simple save as xml operation should cause this error?
> >
> Are you able to save these documents manually to this path, using
File/Save
> As? (Preferably in the same session as when the COM component was
> unsuccessful, so that circumstances are as similar as possible.)
>
> Can you trap this error? And if it occurs, can the COM component save to a
> different location? Or to a different file format?
>
> FWIW, if we're not dealing with a damaged file that for some reason Word
is
> unable to save, it looks like we're dealing more with a hardware issue
than a
> problem in Word...

Thanks for the suggestions Cindy.

The error is happening in Word on the SaveAs method. I'm saving the file in
the folder C:\Temp which happens to be my temp folder. Its not at all a
consistent error - in fact it hardly happens but for a few documents.

Here's my code:

public XML_RETURN_CODE ConvertToXML()
{
object missing = System.Reflection.Missing.Value;
string sXmlFile = Path.ChangeExtension(m_sFilename,"xml");
object oXmlFile = (object)sXmlFile;
object oSaveFormat = 11;
object oReadOnly = false;
XML_RETURN_CODE retCode;

try
{
Log.Write("About to save as xml", true);
//Save as WordML
m_WordDocument.SaveAs(ref oXmlFile, ref oSaveFormat, ref missing,
ref missing, ref missing, ref missing, ref oReadOnly, ref missing, ref
missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref
missing,
ref missing);

Log.Write("xml file " + sXmlFile + " saved successfully", true);

//..some more code here
}
catch (COMException ce)
{
m_sError = "Error saving Word XML file(" + sXmlFile + ") - " +
ce.Message;
Log.Write(m_sError, true);
return XML_RETURN_CODE.XML_CONV_FAIL;
}
catch(Exception e)
{
m_sError = "Error saving Word XML file(" + sXmlFile + ") - " +
e.Message;
Log.Write(m_sError, true);
return XML_RETURN_CODE.XML_CONV_FAIL;
}
finally
{
CloseWordDoc();
}

return retCode;
}


An exception is thrown and the second try..catch block is executed. I'm
beginning to think I should save in a different folder but I can't see why I
should.

Cindy M -WordMVP-
02-23-2006, 09:42 AM
Hi Techie,

> Thanks for the suggestions
>
Did you try any of them? What were the results?

> Its not at all a
> consistent error - in fact it hardly happens but for a few documents.
>
And is it consistent for these documents?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :-)