Click here to Skip to main content
15,889,795 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi..
I want to store/retrieve only image path in database not whole image in database.

thank you
Posted

use getImage to get file path as string and store path to your table

get file path from your table as string, then use ShowImage to show your image

VB
Function getImagePath() As String
       Dim dlg As New OpenFileDialog()
       Dim StrPath As String = ""
       dlg.Filter = "Jpeg Files|*.jpg|All Files|*.*"
       If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
           StrPath = dlg.FileName.ToString
       End If
       Return StrPath
   End Function

   Sub ShowImage(strPath As String)
       If System.IO.File.Exists(strPath) Then
           Dim Img As Image
           Img = New Bitmap(Bitmap.FromFile(strPath))
           PictureBox1.Image = Img
       End If
   End Sub


---
salam
 
Share this answer
 
v3
Comments
chetankhatri 23-Feb-13 4:46am    
thank you very much for reply
in which event of pictureBox1 i have to call getImagePath() function..?
In getimagepath there is no use of picturebox then how it assign to picturebox ,it will display in picturebox?
Just eg 25-Feb-13 1:17am    
as picturebox in vb6??
u can save string path to picturebox1.tag
Store it in a varchar column of your table like any other piece of data.
 
Share this answer
 
Comments
chetankhatri 23-Feb-13 4:35am    
thanks
Rather than storing the entire path in a single VARCHAR column. Try and store the path in a column and the file name in another column.
E.g:- Store E:\Pics\ in column1
and Pic1.jpg in column2
 
Share this answer
 
Comments
chetankhatri 23-Feb-13 4:38am    
thanks
VB
If (FileUpload1.HasFile) Then
                FilePath = Save_InFolder(FileUpload1)
                image = FileUpload1.FileName
           Else
                image = HdImage.Value
                FilePath = ""
            End If

 Private Function Save_InFolder(ByVal FUP As FileUpload) As String
        Try
            Dim hpf As HttpPostedFile = FUP.PostedFile
            Dim SavePath As String = "~/Images/Clinic/"
            Dim fileName As String = FUP.FileName
            Dim SaveName As String = Server.MapPath(SavePath) + fileName
            '--------------Save Image into  Folder---------------
            hpf.SaveAs(SaveName)
            '--------------Save Image Path into Database---------
            SavePath = SavePath + fileName
            Return SavePath
        Catch ex As Exception
        End Try
    End Function
 
Share this answer
 
Comments
chetankhatri 23-Feb-13 4:42am    
thanks
Member 14216312 13-May-19 23:50pm    
How to Insert image in database using only path in vb.net and how to insert database image in crystal report

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900