467,119 Members | 1,015 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,119 developers. It's quick & easy.

Binary file open error

The following code works fine. It opens file reads the data and then
closes.

************************************************** **************************
****************
Dim objFileInfo As FileInfo = new FileInfo(strFilePath)
Dim objStream as StreamReader = objFileInfo.OpenText()
Dim strContents as String = objStream.ReadToEnd()
objStream.Close()
************************************************** **************************
****************

I get an error on the following line with the same file.

Dim fs as FileStream = new FileStream(strFilePath, FileMode.Open)

The error I get is:

************************************************** **************************
****************
Access to the path "c:\QA Docs\QPM 0.00 Table of Contents.doc" is denied.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path
"c:\QA Docs\QPM 0.00 Table of Contents.doc" is denied.

ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or
Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user (typically
IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer,
choose "Properties" and select the Security tab. Click "Add" to add the
appropriate user or group. Highlight the ASP.NET account, and check the
boxes for the desired access.
************************************************** **************************
****************

Why would I be denied access in this procedure and not the one before?

Thanks,

Tom
Nov 18 '05 #1
  • viewed: 1856
Share:
4 Replies
Are they both attempting to open the same file?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
The following code works fine. It opens file reads the data and then
closes.

************************************************** ************************** ****************
Dim objFileInfo As FileInfo = new FileInfo(strFilePath)
Dim objStream as StreamReader = objFileInfo.OpenText()
Dim strContents as String = objStream.ReadToEnd()
objStream.Close()
************************************************** ************************** ****************

I get an error on the following line with the same file.

Dim fs as FileStream = new FileStream(strFilePath, FileMode.Open)

The error I get is:

************************************************** ************************** ****************
Access to the path "c:\QA Docs\QPM 0.00 Table of Contents.doc" is denied.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path
"c:\QA Docs\QPM 0.00 Table of Contents.doc" is denied.

ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user (typically
IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer,
choose "Properties" and select the Security tab. Click "Add" to add the
appropriate user or group. Highlight the ASP.NET account, and check the
boxes for the desired access.
************************************************** ************************** ****************

Why would I be denied access in this procedure and not the one before?

Thanks,

Tom

Nov 18 '05 #2
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:#9**************@TK2MSFTNGP10.phx.gbl...
Are they both attempting to open the same file?
They are.

But not at the same time. I am commenting one out when running the other,
just to get it to work.

Tom.
--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
The following code works fine. It opens file reads the data and then
closes.

************************************************** **************************
****************
Dim objFileInfo As FileInfo = new FileInfo(strFilePath)
Dim objStream as StreamReader = objFileInfo.OpenText()
Dim strContents as String = objStream.ReadToEnd()
objStream.Close()

************************************************** **************************
****************

I get an error on the following line with the same file.

Dim fs as FileStream = new FileStream(strFilePath, FileMode.Open)

The error I get is:

************************************************** **************************
****************
Access to the path "c:\QA Docs\QPM 0.00 Table of Contents.doc" is denied. Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path "c:\QA Docs\QPM 0.00 Table of Contents.doc" is denied.

ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5

or
Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user (typically
IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the
appropriate user or group. Highlight the ASP.NET account, and check the
boxes for the desired access.

************************************************** **************************
****************

Why would I be denied access in this procedure and not the one before?

Thanks,

Tom


Nov 18 '05 #3
"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
The following code works fine. It opens file reads the data and then
closes.

************************************************** ************************** ****************
Dim objFileInfo As FileInfo = new FileInfo(strFilePath)
Dim objStream as StreamReader = objFileInfo.OpenText()
Dim strContents as String = objStream.ReadToEnd()
objStream.Close()
************************************************** ************************** ****************


Try the following:

Dim objReader As StreamReader = New StreamReader(strFilePath)
Dim strContents As String = objReader.ReadToEnd()

BTW, what do you mean when you call this a "binary file"? You're reading the
entire thing into a string, which is a "text file" sort of thing to do. If
you really meant to store binary data, you could try:

Dim objStream As FileStream = New FileStream(strFilePath)
Dim objReader As BinaryReader = New BinaryReader(objStream)
'
Dim i As Integer = objReader.ReadInt32()
Dim s As String = objReader.ReadString()
Dim f As Double = objReader.ReadDouble()

--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #4
"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:10*************@corp.supernews.com...
The following code works fine. It opens file reads the data and then
closes.

************************************************** **************************
****************
Dim objFileInfo As FileInfo = new FileInfo(strFilePath)
Dim objStream as StreamReader = objFileInfo.OpenText()
Dim strContents as String = objStream.ReadToEnd()
objStream.Close()

************************************************** **************************
****************


Try the following:

Dim objReader As StreamReader = New StreamReader(strFilePath)
Dim strContents As String = objReader.ReadToEnd()

BTW, what do you mean when you call this a "binary file"? You're reading

the entire thing into a string, which is a "text file" sort of thing to do. If
you really meant to store binary data, you could try:

Dim objStream As FileStream = New FileStream(strFilePath)
Dim objReader As BinaryReader = New BinaryReader(objStream)
'
Dim i As Integer = objReader.ReadInt32()
Dim s As String = objReader.ReadString()
Dim f As Double = objReader.ReadDouble()

What I meant by Binary, was that I need to read this into a Binary array
that I am going to put into Sql Server as an image. I finally got it to
work using the following:

Dim fs as FileStream = new
FileStream(strFilePath,FileMode.OpenOrCreate,FileA ccess.Read)
Dim arrByteData(objFileInfo.Length) as Byte
fs.Read(arrByteData, 0, fs.Length)
fs.Close()

What I was missing was the FileAccess.Read in the FileStream call (not sure
why that was causing me an error - I assume, it was because without it, I
could be writing also).

I was using OpenText(), because I was copying into a string. I was
originally doing this so I could use the string search functions. But I
can't copy it into Sql Server as a Sring into the image field. I need to
upload it as a Binary ( at least this is the way I was told - I tried
textcopy and that was a disaster).

Tom. --
John Saunders
johnwsaundersiii at hotmail

Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Daniel Moree | last post: by
4 posts views Thread by nguser3552 | last post: by
6 posts views Thread by zl2k | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.