Access is denied with FileStream object

M

Martin

Hi,

I am writing a web service which contains a function that tries to
open up a FileStream.

When I try to do this I get the following error

"Access to the path "C:\Handheld\Images\1100314670.jpg" is denied"

I can do things like CopyFile so don't know how it can be a
permissions problem. I only seem to have a problem with FileStream.

Any thoughts???


<WebMethod(Description:="Get image")> _
Public Function GetImage(ByVal i_code As String) As
Xml.XmlDocument

Try
Dim f1 As IO.File
If Not f1.Exists("C:\Handheld\Images\1100314670.jpg") Then
Return Nothing
End If
Dim F As System.IO.FileStream = New
System.IO.FileStream("C:\Handheld\Images\1100314670.jpg",
IO.FileMode.Open)
Dim binRead As BinaryReader = New BinaryReader(F)

Dim objXml As Xml.XmlTextWriter = New
Xml.XmlTextWriter("C:\Handheld\Test.xml", System.Text.Encoding.UTF8)

objXml.WriteStartDocument()

objXml.WriteStartElement("ct", "ContactDetails",
"http://10.0.0.196/Contact")
objXml.WriteStartElement("image")
objXml.WriteAttributeString("logo", "1100314670.jpg")

Dim readByte As Integer = 0
Dim bytesToRead As Integer = 100

Dim base64Buffer(bytesToRead) As Byte

Do
readByte = binRead.Read(base64Buffer, 0, bytesToRead)
objXml.WriteBase64(base64Buffer, 0, readByte)
Loop While (bytesToRead <= readByte)

objXml.WriteEndElement()

objXml.WriteEndElement()

objXml.WriteEndDocument()

objXml.Flush()
objXml.Close()

Dim xd As Xml.XmlDocument
xd.Load("C:\Handheld\Test.xml")

Return xd

Catch ex As Exception
Return Nothing
'MsgBox("Error in SharScanService." & vbNewLine &
ex.Message)
End Try

End Function
 
K

Kondratyev Denis

Are ASP.NET work process and IIS work process (for IIS 6.0) have read
permissions for this folder?
 
M

Martin

It was just a permissions problem. I thought that giving sharing to
everyone would have been enough but I had to specify permission to the
ASP user.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,204
Latest member
LaverneRua

Latest Threads

Top