I have two image folders in my web server saving the actual image file in both folders. one s_folder for thumbnail and the other l_folder for large images. I want to upload images to these folders and make an entry of the file name in database field.
This pc of my code does save in one folder, passes thru the second folder and enters the record in my database. However, when i check the l_folder the image does not exist. I can use another pair of eyes to find out what am missing. That would be awesome. This is the line does not work "Me.Imgfile.PostedFile.SaveAs(str_l_filepath)"
here is my code:
Thanks
This pc of my code does save in one folder, passes thru the second folder and enters the record in my database. However, when i check the l_folder the image does not exist. I can use another pair of eyes to find out what am missing. That would be awesome. This is the line does not work "Me.Imgfile.PostedFile.SaveAs(str_l_filepath)"
here is my code:
VB.NET:
[SIZE=2]str_s_filepath = str_s_folder & strfilename[/SIZE]
[SIZE=2]str_l_filepath = str_l_folder & strfilename[/SIZE]
[SIZE=2][COLOR=#008000]'strip the type of extn from filename[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] extpos [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = strfilename.LastIndexOf(".")[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ext [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = LCase(strfilename.Substring(extpos))[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] File.Exists(str_s_filepath) [/SIZE][SIZE=2][COLOR=#0000ff]And[/COLOR][/SIZE][SIZE=2] File.Exists(str_l_filepath) [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].lblconfirm.Text = strfilename & " already exits on the server!"[/SIZE]
[SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] ext = ".jpg" [/SIZE][SIZE=2][COLOR=#0000ff]Or[/COLOR][/SIZE][SIZE=2] ext = ".bmp" [/SIZE][SIZE=2][COLOR=#0000ff]Or[/COLOR][/SIZE][SIZE=2] ext = ".gif" [/SIZE][SIZE=2][COLOR=#0000ff]Or[/COLOR][/SIZE][SIZE=2] ext = ".jpeg" [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Imgfile.PostedFile.SaveAs(str_s_filepath)[/SIZE]
[SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Imgfile.PostedFile.SaveAs(str_l_filepath)[/SIZE]
[SIZE=2][COLOR=#008000]'also update the database fields[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sql [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = "Insert into Photo(user_id,photo_date,filename,photo_desc,photo_cat_id)values('" _[/SIZE]
[SIZE=2]& lblowner & "','" & Now.Date & "','" & strfilename & "','" & txt & "','" & ddl & "')"[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] con [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlConnection(Application("connection"))[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] da [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlDataAdapter(sql, con)[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ds [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] DataSet[/SIZE]
[SIZE=2]da.Fill(ds)[/SIZE]
Last edited by a moderator: