Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need to read an image into a datasets table. I have found an example and am trying to learn more about it.. but when I run this.. I get an access denied error . Here is the code.

 

Public Shared Sub LoadAllImages(ByVal MyDataTable As DataTable, ByVal FilePathField As String, ByVal ImageField As String)
       'loop through all the rows and load the images
       For Each dr As DataRow In MyDataTable.Rows
           LoadImage(dr, ImageField, dr.Item(FilePathField))
       Next
   End Sub
   Public Shared Sub LoadImage(ByVal MyDataRow As System.Data.DataRow, ByVal FilePath As String, ByVal ImageField As String)
       Dim fs As New System.IO.FileStream(FilePath, IO.FileMode.Open, System.IO.FileAccess.Read)
       Dim Image(fs.Length) As Byte
       fs.Read(Image, 0, fs.Length)
       fs.Close()
       MyDataRow.Item(ImageField) = Image

   End Sub

and what I'm using to call this

LoadAllImages(ds.Tables(0), "vcFileName", "d:\Image")

when i step through, my access denied error happens on the dim fs as new system.... line. The value coming from the dataset in teh vcFileName column is p01983.jpg. d:\Image is an actaul path.. inside that path is the image file. I am logged in as Administrator of this box and that path is local to my machine. can someone help me understand what I'm doing wrong and right it please.

 

thanks

shannon

JvCoach23

VB.Net newbie

MS Sql Vet

  • Administrators
Posted

Just noticed you are using

d:Image

rather than

d:\Image

in your sample above - is that a type here or in your real code? If that doesn't fix the problem could you post the exact exception type / message that is being thrown along with the full path that it is attempting to read from.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

typeo.. Here is the error message that I'm getting.

[system.UnauthorizedAccessException]: {System.UnauthorizedAccessException}

HelpLink: Nothing

InnerException: Nothing

Message: "Access to the path "d:\Image" is denied."

Source: "mscorlib"

 

Here is the code I changed so that I could get the try and catch to work

Public Shared Sub LoadImage(ByVal MyDataRow As System.Data.DataRow, ByVal FilePath As String, ByVal ImageField As String)
       Dim fs As FileStream
       'Dim fs As New System.IO.FileStream(FilePath, IO.FileMode.Open, System.IO.FileAccess.Read)
       Try
           fs = New FileStream(FilePath, IO.FileMode.Open, System.IO.FileAccess.Read, FileShare.Read)
       Catch ex As Exception
           Throw ex
       End Try

       Dim Image(fs.Length) As Byte
       fs.Read(Image, 0, fs.Length)
       fs.Close()
       MyDataRow.Item(ImageField) = Image

   End Sub

sure hope you can help me out. I'm getting the error in the windows form on the fs=new filestream line.

 

thanks

shannon

JvCoach23

VB.Net newbie

MS Sql Vet

Posted

I got it working. what I thought I was suppose to be passing in was the path on the


       LoadAllImages(ds.Tables(0), "vcFileName", "d:\Image")

 

what it was really looking for was the column that I was going to be stuff the image into. I still don't think I have the image stuffing going quite right.. but one step further.

 

it was suppose to look like this


       LoadAllImages(ds.Tables(0), "vcFileName", "Image")

 

thanks

shannon

JvCoach23

VB.Net newbie

MS Sql Vet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...