Thread: Access Denied
View Single Post
Old May 30th, 2006, 10:10 AM   #2
melbolt
Professional Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 253
Rep Power: 4 melbolt is on a distinguished road
Quote:
Originally Posted by NightShade01
I'm trying to write a simple program that will just open a streamwriter and write a few lines of text to a txt file. However i want the txt file to be under the path c:\program files\file.txt. No matter what i try though the program constantly keeps crashing saying that access is denied to that path. How do i get around this?
here's something to try:

have you tried to make sure the path is valid first?

dim MyPath as string = "c:\program files\file.txt"

try
   if System.IO.File.Exists(MyPath)
       'put code in here
   else
       msgbox("the damn path doesn't exist!!!")
   endif
catch e as exception
   msgbox(e.message)
end try

I know it didn't say there was a file not found file but sometimes the error messages are not smart enough to know this, I had this exact same problem last week due to a stupid mispelling.

If this does not lead you to an answer to your problem, post pack again and we'll try something else.

if this isn't the problem then most likely you have some sort of file permissions set through windows or something.

if it does turn out that the path is not valid, put a breakpoint in your code and see what exactly is in your path variable to see where you went wrong.
__________________
I have never let my schooling interfere with my education. -Mark Twain-

Xbox live gamertag: melbolt
melbolt is offline   Reply With Quote