In my asp.net+vb web with access database there is a page which displays data as per query string and the string is PNO and all data is correctly displayed in gridview and dataview. there is a Image1.ImageUrl and
i used the following code but it is not working
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim PNO As String
PNO = Request.QueryString("PNO")
Image1.ImageUrl = "C:/wing/Photos/" + PNO + ".jpg"
End Sub
When displaying image in web page, use virtual path instead local path like Image1.ImageUrl = "~/wing/Photos/" + PNO + ".jpg". The wing folder can be physical folder or virtual directory under your application (iis virtual directory).
u cannot use local path of image... it must be a virtual path to the web directory.... for example, if "wing" is a name of the folder where u r application is present then, u can do this
Image1.ImageUrl = Server.MapPath("Photoes") + "/" + PNO + ".jpg"
hope this helps...
in a search page of my web the following code is working fine
Dim PNO1 As String = "11022"
PNO1 = " + inputtxt.Text + "
Image1.ImageUrl = "~/Photos/" + PNO + ".jpg"
'Image1.ImageUrl = "C:/Awing/Photos/" + PNO + ".jpg"
'Image1.ImageUrl = "\\ms16eme/Awing/Photos/" + PNO + ".jpg"
End Sub
but when it goes to a string with a hyperlink from another page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim PNO As String
PNO = Request.QueryString("PNO")
Image1.ImageUrl = Server.MapPath("Photos") + "/" + PNO + ".jpg"
End Sub
this is not displaying the image
please suggest a solution
1. Local physical path is used to save your file to server harddisk
example : c:\myweb\myfile.jpg, d:\user\me\project\myweb\file.txt
2. URL is deferent with physical path, its used in your browser
example : http:/domain/myimages/file.jpg
in asp.net control you can use : ~/myimages.jpg
3. ImageUrl, use No 2 sample
4. Server.Mappath is used to determine local physical path when you want to save the file,
dont sever.mappath to set ImageUrl
i tried various codes but not able to process
The main problem is the input is a string (eg kc1432) and the imake name is KC1432.jpg all data from tables displays from database but image from folder is not displayed
Dim PNO As String
PNO = Request.QueryString("PNO")
Image1.ImageUrl = "~/images/" + PNO + ".jpg"
end sub
Place "Images" folder under your application, if you want place it to another location after published. Creare virtual directory "images" under the application.
the photos are placed inside the images folder in my web directory still it is not working
i got a code from a forum as under but i am not able to edit as per my requirement as i use query string
PNO and the file name varies as per the pNO changes
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Request.QueryString("FileName") IsNot Nothing Then
Try
' Read the file and convert it to Byte Array
Dim filePath As String = "C:\images\"
Dim filename As String = Request.QueryString("FileName")
Dim contenttype As String = "image/" & Path.GetExtension(filename).Replace(".", "")
Dim fs As FileStream = New FileStream(filePath & filename, FileMode.Open, FileAccess.Read)
Dim br As BinaryReader = New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(Convert.ToInt32(fs.Length))
br.Close()
fs.Close()
'Write the file to Reponse
Response.Buffer = True
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = contenttype
Response.AddHeader("content-disposition", "attachment;filename=" & filename)
Response.BinaryWrite(bytes)
Response.Flush()
Response.End()
Catch
End Try
End If
End Sub
sir please help me i am in trouble for this code
I tried a lot for solving this problem in different forum & googled a lot. At last i used a trick to solve it
i am binding a string to a label which is PNO
pnotxt.Text = Request.QueryString("PNO")
Dim PNO As String
PNO1 = " + pnotxt.Text + "
Image1.ImageUrl = "~/photos/" + PNO + ".jpg"
end sub
This is not a correct solution but it solved my problem
沒有留言:
張貼留言