Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 28th, 2006, 3:01 PM   #1
NightShade01
Programmer
 
Join Date: Oct 2005
Posts: 52
Rep Power: 4 NightShade01 is on a distinguished road
Access Denied

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?
NightShade01 is offline   Reply With Quote
Old May 30th, 2006, 10:10 AM   #2
melbolt
Professional Programmer
 
melbolt's Avatar
 
Join Date: Feb 2005
Location: PA, USA
Posts: 254
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
Old May 30th, 2006, 11:23 AM   #3
MisterPoppy
Newbie
 
Join Date: Apr 2006
Location: Sweden
Posts: 13
Rep Power: 0 MisterPoppy is on a distinguished road
I'll admit, that I'm not experienced in VB.Net. However. In C# you have to type an '@' before the string to format the text right. You could also try something like this:

string myPath = "c:\\my map\\myfile.txt"
MisterPoppy is offline   Reply With Quote
Old May 30th, 2006, 5:05 PM   #4
mjhoagland
Newbie
 
Join Date: May 2006
Posts: 5
Rep Power: 0 mjhoagland is on a distinguished road
Double slashes won't do anything in VB.NET except put extra slashes in the directory structure you're looking up

What OS are you using? 2000? 2003? XP?
mjhoagland is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:40 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC