472,371 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 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 1511
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: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.