Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

System.UnauthorizedAccessException: Access to the path "..." is denied - stumped!

Posted on 2006-10-24
5
Medium Priority
?
1,461 Views
Last Modified: 2007-12-19
It's the strangest thing. In ASP.NET (on Win2k3), when I try to overwrite an existing file, I always get an UnauthorizedAccessError. Here's the code:


    <WebMethod()> _
    Public Function Save_File() As String
        Dim f As New System.IO.StreamWriter("C:\inetpub\fms4net\files\asdf.txt")
        f.Write("hello world")
        f.Close()
        Return "ok"
    End Function


When I call Save_File() it the first time (the file isn't yet created), no dramas. When I call it the second time, I get the following error:

System.UnauthorizedAccessException: Access to the path &quot;C:\inetpub\fms4net\files\asdf.txt&quot; is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String str)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
   at System.IO.StreamWriter.CreateFile(String path, Boolean append)
   at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
   at System.IO.StreamWriter..ctor(String path)
   at FMS4NET.Test.Save_File() in C:\Documents and Settings\Administrator\VSWebCache\....\TEST\Test.asmx.vb:line 50

I've even tried deleting the file just before writing to it, yet even the delete command fails with the same error:

System.UnauthorizedAccessException: Access to the path &quot;C:\inetpub\fms4net\files\asdf.txt&quot; is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String str)
   at System.IO.File.Delete(String path)
   at FMS4NET.Test.Save_File() in C:\Documents and Settings\Administrator\VSWebCache\....\TEST\Test.asmx.vb:line 50

The file isn't readonly. both MACHINENAME\ASPNET and MACHINENAME\IUSR_MACHINENAME have full control over both the file itself and the containing folder. (ASP.NET's creating hte file initially after all.) I have also recompiled the application (with minor changes to ensure it's actually recompiled) then tried the webmethod immediately afterwards yet it still happens.  Also tried creating the file manually myself in Windows Explorer, same problem occurs.

I feel like an idiot, lol. Any ideas?

Thanks in advance,
-blowfly
0
Comment
Question by:blowfly
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 17795466
Try

<WebMethod()> _
    Public Function Save_File() As String
        Dim f As New System.IO.StreamWriter("C:\inetpub\fms4net\files\asdf.txt")
        f.Write("hello world")
        f.Flush() '<--------------------- added
        f.Close()
        f.Dispose() '<----------------- added
        Return "ok"
    End Function
0
 

Author Comment

by:blowfly
ID: 17800000
No luck I'm afraid - Flush didn't help, and the .Dispose() member isn't available. (VS.NET2003)

Also i'm still unable to delete the file first so something more fundamental is going on. I can still delete the file through Windows Explorer.
0
 

Author Comment

by:blowfly
ID: 17878121
Found the answer - turns out the parent folder needed the MACHINENAME\Users group to have "Modify" access. Rather obvious in hindsight. Problem solved.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18171150
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question