jvcoach23 Posted February 22, 2005 Posted February 22, 2005 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 Quote JvCoach23 VB.Net newbie MS Sql Vet
Administrators PlausiblyDamp Posted February 22, 2005 Administrators Posted February 22, 2005 Are you doing this from an ASP.Net application? If so then you need to make sure your web application has access rather than your login account. Search these forums for several possible solutions. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
jvcoach23 Posted February 22, 2005 Author Posted February 22, 2005 sorry, should have included that.. I'm using a windows form in vb.net thanks Quote JvCoach23 VB.Net newbie MS Sql Vet
jvcoach23 Posted February 24, 2005 Author Posted February 24, 2005 continuing to try to find my way around this error.. Can anyone lend a hand Quote JvCoach23 VB.Net newbie MS Sql Vet
Administrators PlausiblyDamp Posted February 24, 2005 Administrators Posted February 24, 2005 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
jvcoach23 Posted February 24, 2005 Author Posted February 24, 2005 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 Quote JvCoach23 VB.Net newbie MS Sql Vet
jvcoach23 Posted February 24, 2005 Author Posted February 24, 2005 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 Quote JvCoach23 VB.Net newbie MS Sql Vet
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.