473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How do you determine if a file exists before using the StranmReader object?

Is there any better method of determining if a file exists then using the Scripting.FileSystemObject

If I do thi

Dim fs As New System.IO.StreamReader(FileName

and the file does not exist thena n exception is thrown, how can you determine if the file exists before attemptng to open it
Nov 20 '05 #1
8 1572
Yes,

Try:

If System.IO.File.Exists(Filename) Then
....
... Your Code ...
....
End If

--
Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
"Darrell Wesley" <an*******@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
Is there any better method of determining if a file exists then using the
Scripting.FileSystemObject?

If I do this

Dim fs As New System.IO.StreamReader(FileName)

and the file does not exist thena n exception is thrown, how can you
determine if the file exists before attemptng to open it?

Nov 20 '05 #2
"Darrell Wesley" <an*******@discussions.microsoft.com> schrieb
Is there any better method of determining if a file exists then using
the Scripting.FileSystemObject?


io.file.exists(filename)
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
* "Armin Zingler" <az*******@freenet.de> scripsit:
"Darrell Wesley" <an*******@discussions.microsoft.com> schrieb
Is there any better method of determining if a file exists then using
the Scripting.FileSystemObject?


io.file.exists(filename)


.... that should be forbidden with 'Option Strict On' too!
'System.IO.File.Exists' ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
Hi Herfried,
io.file.exists(filename)


... that should be forbidden with 'Option Strict On' too!
'System.IO.File.Exists' ;-).


Vb is not case sensitive and let's keep it that way

Cor
Nov 20 '05 #5
Cor,

* "Cor Ligthert" <no**********@planet.nl> scripsit:
io.file.exists(filename)


... that should be forbidden with 'Option Strict On' too!
'System.IO.File.Exists' ;-).


Vb is not case sensitive and let's keep it that way


I didn't "complain" about case sensitivity but about "qualification" of
a class name with an incomplete namespace hierarchy.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
* "Armin Zingler" <az*******@freenet.de> scripsit:
"Darrell Wesley" <an*******@discussions.microsoft.com> schrieb
Is there any better method of determining if a file exists then
using the Scripting.FileSystemObject?


io.file.exists(filename)


... that should be forbidden with 'Option Strict On' too!
'System.IO.File.Exists' ;-).


I don't see the difference.
--
Armin

Nov 20 '05 #7
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
Cor,

* "Cor Ligthert" <no**********@planet.nl> scripsit:
io.file.exists(filename)

... that should be forbidden with 'Option Strict On' too!
'System.IO.File.Exists' ;-).


Vb is not case sensitive and let's keep it that way


I didn't "complain" about case sensitivity but about "qualification"
of a class name with an incomplete namespace hierarchy.


System is imported by default.
--
Armin

Nov 20 '05 #8
Herfried,

Sorry I am such a superdummy

:-)))))))))))))))

(Of course I did understand what you mean but that answer would come from
Armin as it was)

Cor
Nov 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: JT | last post by:
is there a way to determine if a form object actually exists? if i use the following syntax: varTextField = Request.Form("txtFormField") then varTextField = "" which gives the same result...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
3
by: Web Webon | last post by:
Hi everybody! I wonder if this is possible? I need to determine if a client is using "windows classic folders" or anything else. If I instantiate a Shell ActiveX object is there a way of...
9
by: Adam | last post by:
Can someone please help!! I am trying to figure out what a font is? Assume I am working with a fixed font say Courier 10 point font Question 1: What does this mean 10 point font Question 2:...
6
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error...
2
by: Wayne Wengert | last post by:
I am trying to determine if a file exists on a web site but I cannot get a match. I have verified that the file does exists in the specified directory (I verified the case of the file and directory...
7
by: Stephen E. Weber | last post by:
I need to determine if a file exists using code. I tried using the system.io.file.exists function, that will appears to locate the file if I use the complete filespec, when I move the project to...
17
by: Peter Duniho | last post by:
I searched using Google, on the web and in the newsgroups, and found nothing on this topic. Hopefully that means I just don't understand what I'm supposed to be doing here. :) The problem: ...
7
by: Cramer | last post by:
I'm wondering if there is an easy way to programmatically determine if an assembly is installed in the GAC. This would be similar to our ability to easily determine if a file exists...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.