Reading a text file and reading

H

HardySpicer

In Vista

Dim _gram = New List(Of String)(File.ReadAllLines(App_Path() &
"\grammar.txt"))

Public Function App_Path() As String
Return System.AppDomain.CurrentDomain.BaseDirectory()
End Function

It cannot find the file grammar.txt even though I put it in the Bin
directory. I have tried other directories and specified them .Also it
won't let me write a file to the c drive - permissions are wrong or
some sort. Same code works in Xp.

Hardy
 
F

Family Tree Mike

HardySpicer said:
In Vista

Dim _gram = New List(Of String)(File.ReadAllLines(App_Path() &
"\grammar.txt"))

Public Function App_Path() As String
Return System.AppDomain.CurrentDomain.BaseDirectory()
End Function

It cannot find the file grammar.txt even though I put it in the Bin
directory. I have tried other directories and specified them .Also it
won't let me write a file to the c drive - permissions are wrong or
some sort. Same code works in Xp.

Hardy


You could configure XP to behave similarly regarding the C:\ permissions.
Similarly Vista can be configured to allow this. Regarding finding the text
file, I normally would use Application.StartupPath. What does your code
show in the debugger versus the expected value?
 
H

HardySpicer

You could configure XP to behave similarly regarding the C:\ permissions.
Similarly Vista can be configured to allow this.  Regarding finding thetext
file, I normally would use Application.StartupPath.  What does your code
show in the debugger versus the expected value?

It shows teh right path in the debugger. How do I change Vista?

Hardy
 
H

HardySpicer

You could configure XP to behave similarly regarding the C:\ permissions.
Similarly Vista can be configured to allow this.  Regarding finding thetext
file, I normally would use Application.StartupPath.  What does your code
show in the debugger versus the expected value?

I changed the permission to the c drive and still got for another
program

Access to the path 'C:\answer.txt' is denied.
when trying to write to disk!
 
H

HardySpicer

I changed the permission to the c drive and still got for another
program

Access to the path 'C:\answer.txt' is denied.
when trying to write to disk!

Now I get

A required privilege is not held by the client.

Hardy
 
F

Family Tree Mike

HardySpicer said:
Now I get

A required privilege is not held by the client.

Hardy


A couple of things throw me in the last two posts.

1. "for another program". Why change programs?
2. "A required privelege is not held by the client.". Are you using
remoting? Why the term "Client". That is an unusual system message.
 
T

Tom Shelton

In Vista

Dim _gram = New List(Of String)(File.ReadAllLines(App_Path() &
"\grammar.txt"))

Public Function App_Path() As String
Return System.AppDomain.CurrentDomain.BaseDirectory()
End Function

It cannot find the file grammar.txt even though I put it in the Bin
directory. I have tried other directories and specified them .Also it
won't let me write a file to the c drive - permissions are wrong or
some sort. Same code works in Xp.

Hardy
 
C

Cor Ligthert[MVP]

Harry,

I see a lot of messages here lately which are all about Vista and has not
direct to do with the VB program language.

That Vista acts not as it is wanted by most people is in my idea a little
bit late to tell.

Cor
 
T

Teemu

Tom, have you noticed that there might be something wrong in your news
program?

This message and the other under topic "Declare a fixed-length string"
contained only your name.

-Teemu
 
H

HardySpicer

"Tom Shelton" <[email protected]> kirjoitti viestissä


Tom, have you noticed that there might be something wrong in your news
program?

This message and the other under topic "Declare a fixed-length string"
contained only your name.

 -Teemu

I found that I had to turn off UAC and then it worked. It's all about
permissions - but I don't know how to do this without disabling UAC.
UAC is those annoying pop-up messages that appear every 10 secs or so
when you try to do anything in Vista.

Hardy
 
T

Tom Shelton

Tom, have you noticed that there might be something wrong in your news
program?

No, it's my fault. I strarted to reply - but decided not to ;) I accidently
hit the wrong ke.
 
T

Tom Shelton

I found that I had to turn off UAC and then it worked. It's all about
permissions - but I don't know how to do this without disabling UAC.
UAC is those annoying pop-up messages that appear every 10 secs or so
when you try to do anything in Vista.

Hardy

You problem is that you are not supposed to be writing to the program files
directory. This has been the case for a long time, but Vista actually
enforces this. Actually, non admistrative users in XP would have the same
issue - it's just not the norm for users to be non-admins under XP :)

You will need to create a manifest to be able to turn off UAC for your app, or
you will need to write your data to a more acceptable place :) I believe that
you can use the path returned by System.Envrionment.GetFolderPath and the
System.Environment.SpecialFolder.ApplicationData and
System.Envrionment.SpecialFolder.LocalApplicationData should work...
 
H

HardySpicer

You problem is that you are not supposed to be writing to the program files
directory.  This has been the case for a long time, but Vista actually
enforces this.  Actually, non admistrative users in XP would have the same
issue - it's just not the norm for users to be non-admins under XP :)

You will need to create a manifest to be able to turn off UAC for your app, or
you will need to write your data to a more acceptable place :)  I believe that
you can use the path returned by System.Envrionment.GetFolderPath and the
System.Environment.SpecialFolder.ApplicationData and
System.Envrionment.SpecialFolder.LocalApplicationData should work...  

I write the data to the desktop and it doesn't like that. I believe
this is a step backwards if you cannot use your own Desktop for
storing info. Thanks for that.

Hardy
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
That Vista acts not as it is wanted by most people is in my idea a little
bit late to tell.

Well, but this does not solve the problem.

Vista is different from previous versions of Windows, but in many cases
applications just do not run properly under Vista because developers wrote
code which only "accidentially" worked under previous versions of Windows
;-).
 
D

David Glienna

Just create a sub folder. Vista doesn't allow anythng to write to the ROOT
directory.
Also, the desktop is in a virtualized location, which didn't exist when VB6
was written.

- David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top