Problem Saving using Visual C#.NET

K

koala

Hi,
I'm trying to save a document from a web click as described in the
knowledge base article.

http://support.microsoft.com/kb/316384/EN_US

Instead of using Windows Application I use web application asp button to do
the work. I'm trying to save the document. However, both save and saveAs
doesn't not work for some reason. Here is the code for save:

object fileName = "c:\\MyNewDocument.doc";
oWord.Documents.get_Item(ref fileName).Save();

It gives me this error:System.Runtime.InteropServices.COMException: Bad file
name

When I try to use saveAs as follow:

oDoc.SaveAs(ref fileName, ref missingValue,ref missingValue, ref
missingValue, ref missingValue,ref missingValue, ref missingValue, ref
missingValue,
ref missingValue, ref missingValue, ref missingValue,ref missingValue, ref
missingValue, ref missingValue,ref missingValue, ref missingValue);

It hangs forever and does not go through.

Thanks for the help in advance

Koala
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?a29hbGE=?=,

Note that you've posted in an end-user group, and the chances of getting a
reply to a C# question are vanishingly remote. You should be posting in an
office.developer newsgroup. But see below...
Instead of using Windows Application I use web application asp button to do
the work. I'm trying to save the document. However, both save and saveAs
doesn't not work for some reason. Here is the code for save:

object fileName = "c:\\MyNewDocument.doc";
oWord.Documents.get_Item(ref fileName).Save();

It gives me this error:System.Runtime.InteropServices.COMException: Bad file
name
I'm a bit vague with this in C#; I know that sometimes you need to specify
double backslashes in order to get a single one in the result; other times not.
Do you have any way of testing whether what's getting passed through ref
fileName contains single or double backslashes? Word will accept only one...

And, generally, you'd refer to an open document with only the file name (and
not the full path). You might want to see if Word accepts that.

You might also see if oWord.Documents[1].Save will work - just to test whether
save is working at all.

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