PC Review


Reply
Thread Tools Rate Thread

check for File In Use

 
 
Devhead
Guest
Posts: n/a
 
      9th Feb 2005
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();

}


 
Reply With Quote
 
 
 
 
Cindy M -WordMVP-
Guest
Posts: n/a
 
      14th Feb 2005
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 :-)

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
search file and export selected file using check boxes into a fold =?Utf-8?B?RS1tYWlsIHJlcG9ydCB1c2luZyBMb3R1cyBOb3Rl Microsoft Access 0 12th Sep 2007 10:36 PM
code to check file size everytime an Excel file is opened Kaiser Microsoft Excel Programming 2 30th Jul 2006 05:46 PM
File check in/check out question Ronald S. Cook Microsoft C# .NET 4 29th Mar 2006 02:12 PM
File Locks after First Check Out and Cant Check back in =?Utf-8?B?TWFyayBMdXR6?= Microsoft Frontpage 0 29th Dec 2005 02:56 PM
ntfrs.jdb file over 400 megs. How to I check to ensure file replication is working... jimbo Microsoft Windows 2000 Networking 0 22nd Jul 2003 04:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:26 AM.