Error saving Word document as XML

T

techie

My COM component is automating Word 2003. For the vast majority of Word
documents there are no problems. However, for some documents I get an error
like this when the program tries to save the Word document as an xml file:

A file error has occurred.

Try one or more of the following:

* Check the disk drive to make sure the disk is properly inserted.

* Check the disk or the disk drive to make sure there is not a hardware
problem.

* Check the network connections.

The location where its trying to save Word is C:\Temp. There shouldn't be
any problem saving there because there's plenty of disk space remaining and
everyone has permissions to save there.

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?

techie
 
C

Cindy M -WordMVP-

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...

Note: in case you hadn't noticed, you're posting your development questions in
an end-user oriented group. You're more likely to get a quicker response, at
the level you're looking for, in one of the Word.VBA groups, or possibly an
office.developer group.

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 :)
 
T

techie

Cindy M -WordMVP- said:
Hi Techie,

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.
 
C

Cindy M -WordMVP-

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 :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top