Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 26th, 2004, 06:42 PM
Authorized User
Join Date: Sep 2003
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to flyin
Default Checking if a file is already opened before writin

Hello everyone, i am using VB.NET, actually that doesn't really matter, or it may, but anyways i have a question about writing files.

I am implementing a system where if you write an article, it updates the RSS representation of that topic, and well, if two processes are trying to write the same file "foo.xml" it bombs and makes me very angry! Is there a way to check to see if the file is already open or in use?

in essence i want,

if isFileOpen("foo.xml") OR isFileLockedBySomeProccess("foo.xml") then
 ' Don't do anything
  exit sub
end if

thanks everyone

Old February 27th, 2004, 11:46 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

When it bombs, note the exception that is thrown. Then use a try...catch block to catch that exception type and handle the error.

    'try saving the file
Catch e As <the exception you see when it bombs>
    'Tell the user that the file can't be saved
    'Do stuff that's applicable to either success or failure
End Try

Work smarter, not harder.

Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking the contents of a text file for log-in Seifer Classic ASP Basics 10 December 18th, 2006 12:45 PM
checking file exists on remote server pete_m Classic ASP Basics 11 August 2nd, 2004 02:35 AM
Adodb.stream File could not be opened. irabba Javascript 6 July 6th, 2004 06:25 AM
Copy cells from an excel file opened in a browser escorido Excel VBA 0 July 6th, 2004 01:44 AM
checking the existence of a file in a webdatabase TwoDee Excel VBA 0 January 14th, 2004 11:28 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.