Unauthorized Access problem writing file

I am getting an unauthorized access exception when i try to write to file in the temp directory.  I think that i have added the appropriate premissions through iis but i guess not.

 anonomyous access is checked and integrated windows authentication is checked

i have also added impersonation = true  to the web.config.

here is the code it is bombing on

Public Function getImageFile() As String
            Dim s As Stream
            Dim i As Image
            Dim b() As Byte
                Kill(StartupPath & "\temp\gemini.tx")
            Catch ex As Exception

            End Try
       ------->>>    Dim fs As FileStream = IO.File.OpenWrite(StartupPath & "\temp\gemini.tx")
            b = z_dTable.Rows(z_index)("cutedoc_image")
            fs.Write(b, 0, b.Length)
            Return fs.Name
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

Any ideas?
Who is Participating?
Melih SARICAConnect With a Mentor OwnerCommented:
ASPNet user must ave write and delete permission on startup folder and sub folders
And also.. The windows account which is running the ASP.NET application pool ( normally localservice account)

SammyConnect With a Mentor Commented:
in IIS did you have Read/Write permission for the file and the containing folder?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.