check for File In Use

D

Devhead

i have an MS Word Document that i have created from an SQL server db and
once created it is opened. If i try to create the same document with the
same filename, i get an error. how do i check to see if this document is
already opened and if so, close it before i attempted to overwrite it. a
code snippet would be helpful. my code as it currently exists follows:
public static void Blob2File(byte[] aDataColumn)

{

byte[] byteBlob;

FileStream fs = null;


//blob field

byteBlob = aDataColumn;

//try-catch added to trap exception when user attempts create document that
is already open

//however, re-examine at a later time. would like to open current document
and not open another document as a copy.

fs = new FileStream(FilePath, FileMode.Create);

fs.Write(byteBlob,0,byteBlob.Length);

fs.Close();

}
 
C

Cindy M -WordMVP-

Hi Devhead,

Traditionally, what one has done is to try opening the file using the same
commands as one would use to open text files for reading/writing. If the
file is already opened, this returns a trappable error. (We never actually
USE a document in this manner, but only use "Open" to test availability.)

Another possible approach is to check for a ~*.doc file (~ followed by the
file name) in the same folder. If one exists, the document is opened and
locked by Windows for editing.
i have an MS Word Document that i have created from an SQL server db and
once created it is opened. If i try to create the same document with the
same filename, i get an error. how do i check to see if this document is
already opened and if so, close it before i attempted to overwrite it. a
code snippet would be helpful. my code as it currently exists follows:
public static void Blob2File(byte[] aDataColumn)

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