473,785 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem Checking If A File Exists In VB.NET

4 New Member
Hi,
I'm checking if a file exists with the following code;

Expand|Select|Wrap|Line Numbers
  1. If System.IO.File.Exists("C:\test.txt") = True Then
  2.      MsgBox("File Exists")
  3. Else
  4.       MsgBox("File Does Not Exist")
  5. End If
For some reason it always returns false even though the file does exist. Any suggestions? Could this be a security issue?
Jun 4 '07
13 24197
Frinavale
9,735 Recognized Expert Moderator Expert
I was just about to say, it's probably because your application is running under a Windows user account with permissions that don't let you access the C:\ directory.

-Frinny
Dec 15 '09 #11
Plater
7,872 Recognized Expert Expert
If you don't have permision, a security exception should have been thrown
Dec 15 '09 #12
toirleach
1 New Member
All,

I just had the same problem here on VS2005. It worked fine on my own PC and even worked from my PC when run from a network drive. I then tested it from another PC and it wouldn't work from the network drive. No exceptions thrown or anything. File.Exists just returned false for a file that existed. Directory.Exist s did the same for a directory that existed.

I then copied the exe onto the required PC and it worked fine!!

Bit of a pain!! An hour of my life gone!! :)

T.
Aug 30 '10 #13
Plater
7,872 Recognized Expert Expert
.NET apps running from a network drive run under a different set of "rules" (they have the "zones" management style like that of internet explorer)
There are some hoops you can jump through to get it to owkr (configure per computer, use clickOnce deployment) but it is probably easier to just run the app locally.
Aug 31 '10 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1113
by: matt dittman | last post by:
I have created a windows service that reads emails from a drop directory and moves them to the appropriate mail folder every 15 seconds. I can move, rename and delete the files as needed, up until the CDO.DropDirectory.GetMessages() method is called. At this point, the files are locked until I shut down the service. After processing and delivery, I need to be able to delete all the files in the drop directory. I can delete them via...
13
2784
by: ashu | last post by:
hi to all, Please read the following ques. first. assume that a bank maintains 2 kinds of accounts for customers one called as savings accounts & other as current account. the savings account provides simple interest & withdraw facilities but no check book facilities. the current account provides check book facilities but no interest.
15
114213
by: Geiregat Jonas | last post by:
is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); } a good way of checking if a file exists or not, if not how should I do it ?
2
4550
by: jcrouse | last post by:
I apologize for starting another thread but the old one had a weird subject line. Anyways...here is the code: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim strInput As String = Application.StartupPath & "\CreateMameGamesCFG.bat" If lblMameExePath.Text <> "" Then
9
2519
by: weidongtom | last post by:
Hi, I've written the code that follows, and I use the function add_word(), it seems to work fine *before* increase_arrays() is called that uses realloc() to allocate more memory to words. But *after* calling increase_arrays(), I received segmentation fault. I tried to step it through gdb, and I found out that after calling increase_arrays(), words's original value is modified, and if I tried to access it, I get <address 0x11 out of...
2
3476
by: Bart | last post by:
Hi, i use the FileUpload control but if the uploaded file already exists, i want let the choice between overwriting or not the existing file. Therefore i use a radiobuttonlist with 'yes' and 'no'. I get no error, but if i take 'yes', the new file which overwrites the existing one is empty. I think it's because of the postabck caused by the radiobuttonlist, so the Fileupload control looses the chosen file. I put the...
7
19119
by: sprash | last post by:
Newbie question: I'm trying to determine if a file physically exists regardless of the permissions on it Using File.Exists() returns false if it physically exists but the process does not have the necessary permissions. One hack could be to check for length and that would throw a FileNotFoundException ...but there is got to be a better way!
20
2172
by: ongaro.admin | last post by:
Hi, I'm experiencing a strange problem with .mdb files. We have two buildings connected by optical fiber (a single LAN). Everything works perfect with any file, any size, any application software. The hardware has been tested several times. Viruses, trojans and so on: clean for sure. The problem is that .mdb files (_only .mdb files_) often don't open, are very slow, or even get crashed and corrupted. The weird is that even copying them...
4
14999
by: ndedhia1 | last post by:
Hi. I am writing a java program in which I want to ftp a file to another unix box. First I have to check if the directory exists in which I am ftping into and if it does not exist, I have to create it: this is the code that I am using that is not working properly: System.out.println("YOU ARE IN UPLOAD"); System.out.println("THIS IS THE HOST: " + host); SshClient ssh = new SshClient();
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10090
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
9949
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...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6739
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();...
1
4050
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
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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.