File IO - Access to path "xxx" is denied Error

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

I am getting an "Access to the path "xxxx" is denied error.

I believe is because the file that I am writing to programatically is being
read/written to by another end user. These files have the same file name and
must have the same file name. I am essentially overwrite an existing file
that is being used by another user.

My question: Is there some method or property in the IO class that will
allow me to CHECK to see if it is safe to try and write to that file name?

TIA.
 
More likely the problem is in the asp.net process not having enough rights
to access the path.

If the problem is in another user trying to access the file, you can just
try opening the file in a loop for a few seconds with catching exceptions.
But it is not a good idea to make a web application wait for this sort of
things. What is the file for anyway?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
I am getting an "Access to the path "xxxx" is denied error.

I believe is because the file that I am writing to programatically is being
read/written to by another end user. These files have the same file name and
must have the same file name. I am essentially overwrite an existing file
that is being used by another user.

My question: Is there some method or property in the IO class that will
allow me to CHECK to see if it is safe to try and write to that file name?

TIA.

A common type of error in these kind of programs is that we keep the
file handle open and when we try to access file next time, it gives
you access denied error.
Please check whether you have closed the file handle properly.
Also check whether you can find that file in Task Manager processes
tab ??
These all are guesses and may not apply.
 
Thanks for your assistance.

No this is the process.

- I grab data and write it to a file.
- That file is then included in an intranet page. A user opens (i.e. reads)
that page and leaves it open in their browser. This "locks" the file (I
think).
- I then grab data again programatically (scheduled task) and I try to
programmatically overwrite the file that is already open by the intranet
user. An error occurs.

I am trying to eliminate the error but first programmatically checking to
determine if the file is "open" or it is not open and I can safely write to
it.

I do not see anywhere for that check. I know I can trap the error but I
would rather not do that.




Eliyahu Goldin said:
More likely the problem is in the asp.net process not having enough rights
to access the path.

If the problem is in another user trying to access the file, you can just
try opening the file in a loop for a few seconds with catching exceptions.
But it is not a good idea to make a web application wait for this sort of
things. What is the file for anyway?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Paul said:
I am getting an "Access to the path "xxxx" is denied error.

I believe is because the file that I am writing to programatically is
being
read/written to by another end user. These files have the same file name
and
must have the same file name. I am essentially overwrite an existing file
that is being used by another user.

My question: Is there some method or property in the IO class that will
allow me to CHECK to see if it is safe to try and write to that file name?

TIA.
 
I close the IO StreamWriter right after I am done with the Write. See my
response above to Eliyahu for a more detailed explanation of what I am doing.

Thanks for your assistance.
 
- That file is then included in an intranet page. A user opens (i.e.
reads)
that page and leaves it open in their browser. This "locks" the file (I
think).
Once the file has been streamed down to the client's browser, there is no
more connection between the file and the client. The file can't be locked
because of this. I still think you are more likely having permission
problems.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Paul said:
Thanks for your assistance.

No this is the process.

- I grab data and write it to a file.
- That file is then included in an intranet page. A user opens (i.e.
reads)
that page and leaves it open in their browser. This "locks" the file (I
think).
- I then grab data again programatically (scheduled task) and I try to
programmatically overwrite the file that is already open by the intranet
user. An error occurs.

I am trying to eliminate the error but first programmatically checking to
determine if the file is "open" or it is not open and I can safely write
to
it.

I do not see anywhere for that check. I know I can trap the error but I
would rather not do that.




Eliyahu Goldin said:
More likely the problem is in the asp.net process not having enough
rights
to access the path.

If the problem is in another user trying to access the file, you can just
try opening the file in a loop for a few seconds with catching
exceptions.
But it is not a good idea to make a web application wait for this sort of
things. What is the file for anyway?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Paul said:
I am getting an "Access to the path "xxxx" is denied error.

I believe is because the file that I am writing to programatically is
being
read/written to by another end user. These files have the same file
name
and
must have the same file name. I am essentially overwrite an existing
file
that is being used by another user.

My question: Is there some method or property in the IO class that will
allow me to CHECK to see if it is safe to try and write to that file
name?

TIA.
 
Thanks for your assistance.

No this is the process.

- I grab data and write it to a file.
- That file is then included in an intranet page. A user opens (i.e. reads)
that page and leaves it open in their browser. This "locks" the file (I
think).
- I then grab data again programatically (scheduled task) and I try to
programmatically overwrite the file that is already open by the intranet
user. An error occurs.

I am trying to eliminate the error but first programmatically checking to
determine if the file is "open" or it is not open and I can safely write to
it.

I do not see anywhere for that check. I know I can trap the error but I
would rather not do that.



Eliyahu Goldin said:
More likely the problem is in the asp.net process not having enough rights
to access the path.
If the problem is in another user trying to access the file, you can just
try opening the file in a loop for a few seconds with catching exceptions.
But it is not a good idea to make a web application wait for this sort of
things. What is the file for anyway?
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net

- Show quoted text -

Try to create a file and overwrite it without letting user open it. If
it doesn't work - it's a permissions issue.
 
Back
Top