Free Support Forum - aspose.com

Problem Saving the document

Hi,

I do have a problem saving a document. The problem is i created a word doc programatically, but when i modified it and saved there is no problem and it works good. But the problem is when i modify the word doc manually and save it and then when i access it programatically and perform some modifications and saving then, it is giving an exception

"Access to the path 'd:\deleteMe\Test.doc' is denied."

The above exception is thrown when it encounters the statement

doc.Save("d:\deleteMe\Test.doc").

Why the same exception not thrown if the doc is not modified manually.

You should know that MS Word blocks the access to the document it opens. That’s why you cannot open or save by Aspose.Words the documents that are held opened by MS Word.

Thanks for your reply,

Ya i too know that MS-Word blocks the opened document.

If i'm trying to access the doc which is opened by MS-Word i was getting the error:

"The process cannot access the file 'd:\deleteMe\Test.doc' because it is being used by another process."

I'm not even able to access the doc. But my proble is different

The steps i have done are:

I created a doc with some data programatically

Then i opened the doc using MS-Word and did some modifications and closed the doc by saving the doc.

Now i'm able to programatically access the doc, as it is closed. But if i'm doing any modifications to the doc and saving the doc, then the exception is raised. And one more thing if i'm saving the doc with another file name then no issue, if i'm saving the doc with the same name, then the exception is raised.

Below is the code:

protected void Button3_Click(object sender, EventArgs e)

{

Document doc = new Document(@"d:\deleteMe\Test.doc");

NodeCollection runs = doc.GetChildNodes(NodeType.Run, true);

foreach(Run rn in runs)

{

rn.Font.Name = "Times New Roman";

rn.Font.Size = 12;

rn.Font.Bold = false;

rn.Font.Underline = Underline.None;

rn.Font.Color = System.Drawing.Color.Blue;

}

doc.Save(@"d:\deleteMe\Test.doc");

}

I was getting error on the lastline that is doc.Save, if i'm saving with another filename no issue, but if the same file name i am getting error.

I have composed a small test to check for this problem:

string filename = Application.StartupPath + @"\TestDoc.doc";

Document doc = new Document(filename);

MessageBox.Show("Now edit and save document 'TestDoc.doc' in MS Word. Then press OK");

doc.Save(filename);

but I haven't got any exception in the end. Please provide us the test project that will alow to reproduce the error.