473,698 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.FileS ystemObject

If I do thi

Dim fs As New System.IO.Strea mReader(FileNam e

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 1588
Yes,

Try:

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

--
Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@h eadfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
"Darrell Wesley" <an*******@disc ussions.microso ft.com> wrote in message
news:93******** *************** ***********@mic rosoft.com...
Is there any better method of determining if a file exists then using the
Scripting.FileS ystemObject?

If I do this

Dim fs As New System.IO.Strea mReader(FileNam e)

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*******@disc ussions.microso ft.com> schrieb
Is there any better method of determining if a file exists then using
the Scripting.FileS ystemObject?


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*******@free net.de> scripsit:
"Darrell Wesley" <an*******@disc ussions.microso ft.com> schrieb
Is there any better method of determining if a file exists then using
the Scripting.FileS ystemObject?


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**********@p lanet.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 "qualificat ion" 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*******@free net.de> scripsit:
"Darrell Wesley" <an*******@disc ussions.microso ft.com> schrieb
Is there any better method of determining if a file exists then
using the Scripting.FileS ystemObject?


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**********@p lanet.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 "qualificat ion"
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
12922
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 whether the input field "txtFormField" doesn't exist or it does exist but it was left empty why can't i use something like?
18
2882
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 that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
3
1912
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 obtaining this information from javascript? (I know that the user will get prompted about allowing such an operation, but I am willing to live with this). Because of the way one of my pages work, I need to know this information in order to "cover up"...
9
19528
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: How do I determine how many characters I can get on a line Question 3: How do I determine how many lines I can get on a page. Assume no margins Question 4: Does their exist some kind of refernce table that will equate a font with chars/line and...
6
10211
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 message: "The process cannot access the file "whatever" because it is being used by another process." I've even tried opening another file using the same streamwriter object before deleting the original file, but it's no use. Something keeps...
2
1720
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 name). The code (below) is from one of my aspx pages. Is there something here I overlooked? Wayne ======================= code ======================= If File.Exists(Server.MapPath("./scores/" & strCurrEventID & ".pdf")) Then
7
3725
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 the web server, that command will not work because I can not specify the entire path, just the path relative to the default project folder. Example This is the path my image property uses: "~/image/NoImageAvailable.jpg"
17
8022
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: I am trying to use the SaveFileDialog class to get a filename, which is subsequently opened for writing (write access, read sharing, but using read/write sharing doesn't make the problem go away anyway). Sometimes, on the statement where I...
7
7618
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 (File.Exists(path)) - but for an assembly, of a particular version, etc in the GAC. I have googled this and failed to find anything useful. Thanks
0
8601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.