How to read a text file?
am 07.04.2008 18:51:40 von quinn
Hi,
I add a folder to my web application, the folder name is "Text" and I put
one text file (1.txt) in the folder. in Default.aspx.vb load event, I try to
open this text file:
dim fs as new io.filestream(server.mappath("test\1.txt"),filemode.open)
dim sr as new io.streamreader(fs)
dim s as string=sr.readtoend
sr.close
response.write (s)
I got a error saying "access to path is denied".
How do I resolve this problem?
Regards
Quinn
Re: How to read a text file?
am 07.04.2008 19:06:32 von George Ter-Saakov
Usually "access denied" is resolved by giving permissions to the appropriate
account.
In your case it's ASPNET account... needs to have "Read" permissions.
Also change this
dim fs as new io.filestream(server.mappath("test\1.txt"),filemode.open)
to
dim fs as new io.filestream(server.mappath("test\1.txt"),filemode.open,
FileAccess.Read)
otherwise it will require write/modify permissions as well
George.
"Quinn" wrote in message
news:elAck%23MmIHA.1680@TK2MSFTNGP06.phx.gbl...
> Hi,
>
> I add a folder to my web application, the folder name is "Text" and I put
> one text file (1.txt) in the folder. in Default.aspx.vb load event, I try
> to open this text file:
>
> dim fs as new io.filestream(server.mappath("test\1.txt"),filemode.open)
> dim sr as new io.streamreader(fs)
> dim s as string=sr.readtoend
> sr.close
>
> response.write (s)
>
> I got a error saying "access to path is denied".
>
> How do I resolve this problem?
>
> Regards
>
> Quinn
>
Re: How to read a text file?
am 07.04.2008 19:06:59 von Norman Yuan
You need to make sure the ASP.NET running user account (hopefully, you know
which user account is used/configured by you to run the ASP.NET application)
have at least "read" permission to that folder.
"Quinn" wrote in message
news:elAck%23MmIHA.1680@TK2MSFTNGP06.phx.gbl...
> Hi,
>
> I add a folder to my web application, the folder name is "Text" and I put
> one text file (1.txt) in the folder. in Default.aspx.vb load event, I try
> to open this text file:
>
> dim fs as new io.filestream(server.mappath("test\1.txt"),filemode.open)
> dim sr as new io.streamreader(fs)
> dim s as string=sr.readtoend
> sr.close
>
> response.write (s)
>
> I got a error saying "access to path is denied".
>
> How do I resolve this problem?
>
> Regards
>
> Quinn
>