Word Automation speed issue

  • Thread starter Thread starter Devhead
  • Start date Start date
D

Devhead

i need to open a Word Document from sql server database, make updates to the
document, then save as READ-ONLY. Basically, this will be a view of the
document that user cannot change. updates to the document are done by
reading field data from the database into the document.

i can read the blob doc to file on local PC but i have noticed some speed
losses viewing the document READ-ONLY vs viewing without this condition.
please see code in question below. it seems like a waste of run time to have
to Save the Document, Close it, then Open it Read-Only but that's the only
way i know how unless someone else out there has a faster way. please
respond if so. thanks.


if ((bool) oReadOnly)

{


oDoc.SaveAs(ref oFilePath, ref oMissing, ref oMissing, ref oMissing, ref
oMissing,

ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing,

ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

oDoc.Close(ref oMissing, ref oMissing, ref oMissing);

oDoc = oWord.Documents.Open(ref oFilePath, ref oMissing, ref oReadOnly, ref
oMissing, ref oMissing,

ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing,

ref oMissing, ref oMissing, ref oMissing, ref oMissing);

File.SetAttributes((string) oFilePath,System.IO.FileAttributes.ReadOnly);

}

else

{

oDoc.SaveAs(ref oFilePath, ref oMissing, ref oMissing, ref oMissing, ref
oMissing,

ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref
oMissing,

ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

}
 
This is what I understand...
1- get blob from db and create a file on local drive of type *.doc
2- update it
3- save local file back to db and mark it has readonly
4- do the step 1 again for view

if this is the condition then you do not have to get the file again from db,
you can mark (attrib) the local copy readonly while saving back to db. this
will avoid fetching for file again.
 
Back
Top