I know this has been asked before. Yes, i did my research but it doesn't seem to be working for me so i hope you experts can help me out :)
Here's what my Project looks like
http://i.stack.imgur.com/nnPZJ.png
Yes, the Build Action is Embedded Resource. I also added this in the AssemblyInfo
Assembly: WebResource("WFL.WebResource.EXT.XXX.png", "image/png")
So now, in the default.aspx i say
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim cs As ClientScriptManager = Page.ClientScript
Dim strReturn As String = cs.GetWebResourceUrl(Me.GetType(), "WFL.WebResource.EXT.XXX.png")
Dim strReturn2 As String = cs.GetWebResourceUrl(GetType(_Default), "WFL.WebResource.EXT.XXX.png")
Image1.ImageUrl = "http://localhost" + strReturn
Image2.ImageUrl = "http://localhost" + strReturn2
Response.Write("http://localhost" + strReturn)
Response.Write("http://localhost" + strReturn2)
End Sub
But when accessing the returned URL, i get The resource cannot be found.
What am i doing wrong?
Thanks in advance.
This being VB and not C#, you don't need the .EXT portion in WFL.WebResource.Ext.XXX.png. That is something C# needs (to specify folder paths), but VB doesn't. You just want your namespace then resource. Try WFL.WebResource.XXX.png and see if that works.
Related
I' m new in this, also I'm new in Visual Basic and Sql Server, and I'm Chile...
Well, I have a question, I've been thinking for several days and can not solve.
I need to show an image in a web form of a client when he wants to see your information.
For that, I have the next sources:
Table Client
email(varchar), nameClient(varchar), nameImage(varchar)
Table Image
nameImage(varchar), image(image)
I have the next proc:
select c.email, c.nameClient, i.image
from Client as c join Image as i on c.nameImage=i.nameImage
In asp.net, I have a web Form as VerCliente.aspx, and in VerCliente.aspx.vb I have this:
Partial Class Default19
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
MostrarNombreCliente.Text = Session("correo")
End Sub
Protected Sub BotonMostrarPerfil_Click(sender As Object, e As EventArgs) Handles BotonMostrarPerfil.Click
Dim numero As Integer
Dim dvSql As Data.DataView = DirectCast(SqlDataSource1.Select(DataSourceSelectArguments.Empty), Data.DataView)
'of this way I do the connection to BD'
If dvSql.Count > 0 Then
numero = 1
'to display the information in the textbox Iam occupying session variables'
Session("email") = dvSql(0).Item(0)
MostrarEmail.Text = Session("email")
Session("nombre") = dvSql(0).Item(1)
MostrarNombreCompleto.Text = Session("nombre")
in VerCliente.aspx I have this , and I would display the image on it
asp:Image ID="MostrarImagen" runat="server" Height="191px" Width="270px" /
but I dont know how to occupy session variables here
MostrarImagen.ImageUrl....(I dont know How )
I tried this but it does not work
Session("imagen") = dvSql(0).Item(2)
MostrarImagen.ImageUrl.ImageUrl = Session("imagen")
End If
End Sub
End Class
thank....bye!!!
Well, after of I'm trying many times, finally I can to resolve my problem, howerer I think that the way that I did the new solution is quite different to how I had posed my problem, but the important is that my solution works fine...
Here is my solution, I hope that can to be of utility for you..
Thank for your comments!!!
Session("imagen") = dvSql(0).Item(8)
If (Context.Session("imagen")) IsNot Nothing Then
Dim image As Byte() = DirectCast(Context.Session("imagen"), Byte())
Dim base64String As String = Convert.ToBase64String(image, 0, image.Length)
Image1.ImageUrl = Convert.ToString("data:image/png;base64,") & base64String
Image1.Visible = True
End If
I have run into a problem in my asp.net and vb.net programming. I have made a website which connects to a database to authenticate users. I have made another page which my windows form application uses to authenticate users so the program does not have to connect directly to the MySql Database as this is insecure.
So far, the code for my asp.net page is:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If Request.QueryString.Keys(0) = "key" And Request.QueryString.Keys(1) = "getapikeyv1" And Request.QueryString.Keys(2) = "authapienc2" Then
Dim key As String = Request.QueryString.Get("key")
If key = "dua9r3rqpK{WPDWp9r93af03r8yqrEPIF{A}W~DW)D08q3raewdawdug9q8wdyaw9wq" Then
returnLabel.Text = "XYeJay4XVh6amvf1kJ34Y6y6hR0sSokP9oJFsi0Mxl4QB0T86W0iac9o2nRfCmFmsONq6sPz+rdX+/NqFk3inHRGnwnqf0IsQXE/M/SvnvY="
Else
returnLabel.Text = "invk"
End If
Else
returnLabel.Text = "invalidrequest"
End If
End If
End Sub
The default value for 'returnLabel' is INVALIDREQUEST. My api keys defined above are working fine so are not needed to be considered here. However, when I use the following code to communicate with the webpage, it always returns with returnLabel's value as 'INVALIDREQUEST'. Even if I put the returnLabel.Text = "1233" at the beginning of the Me.Load sub, the page still returns INVALIDREQUEST when I communicate with it through my program!
I use this code to request:
Try
Dim APIRequest As New WebClient
APIRequest.QueryString.Add("key", r9j0wqfha0fh0wf0.DecryptString128Bit(APIKey5, dVadaihwdq93ra0w0))
APIRequest.QueryString.Add("getapikeyv1", "")
APIRequest.QueryString.Add("authapienc2", "")
Dim ako39rqwfa As String = APIRequest.DownloadString(EncryptionPageUrl)
MsgBox(ako39rqwfa)
Dim m As Match = Regex.Match(ako39rqwfa, "<span id=""returnLabel"">.*?</span>")
APIKey00 = m.Value.Replace("<span id=""returnLabel"">", "").Replace("</span>", "")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
As you can see, the WebClient I use is fine but the Me.Load sub in the webpage is not responding the request made by the program...
Is there any way I can make the webpage respond to the WebClient.DownloadString() function?
Thanks,
Rodit
(ps. c# or vb code would be appreciated)
Change your asp.net page to check the query string like this, not sure if you can assume they are in a certain order:
If Request.QueryString.Get("key") isnot nothing And
Request.QueryString.Get("getapikeyv1") isnot nothing And
Request.QueryString.Get("authapienc2") isnot nothing Then
I want to use the Sector variable that is sent to the SetSectorImage sub to name the image that is being changed (the images do already exist on the web form, I am only changing the URLs). A Google search only led me to an article on MSDN about the CallByName method but I don't know if it will work in this situation and of it will, I can't figure out how.
Here's the article if it helps: http://msdn.microsoft.com/en-us/library/22x2chfx.aspx
Imports System
Imports System.IO
Public Class Launcher
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SetSectorImage("Sector1")
SetSectorImage("Sector2")
SetSectorImage("Sector3")
End Sub
Sub SetSectorImage(Sector As String)
Dim SectorStatus As String
Try
Using Reader As New StreamReader(Sector + ".txt")
SectorStatus = Reader.ReadToEnd()
Reader.Close()
Sector_SHOULD_BE_USED_HERE.ImageUrl = ("~/Images/" + SectorStatus)
End Using
Catch ex As Exception
ErrorMessage.Text = ("There was an error reading the status of: " + Sector)
ErrorMessage.Visible = True
End Try
End Sub
End Class
Let's suppose you have Images on the page:
<asp:Image ID="Sector1" />
<asp:Image ID="Sector2" />
<asp:Image ID="Sector3" />
You can access them with Control.FindControl Method
Dim myControl1 As Control = FindControl(Sector)
Dim myImage As Image = myControl1
myImage.ImageUrl = ("~/Images/" + SectorStatus)
I did some more research on CallByName() and found that I can use it in this situation. The line to change the image URL would be:
CallByName(Sector, "ImageUrl", CallType.Set, "~/Images/" + SectorStatus)
Issue: Unable to display image using FilePath
I have File Upload button which captured the file path & when I click on Upload button, it should be display the image which I have selected. But its not happening?
What I missed here?? do I need to convert the path to image url?? If Yes then please provide me the code behind it??
Thanks in advance..
Here is my code....
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim path As String
path = Server.MapPath(FileUpload1.FileName)
Image1.ImageUrl = path
Label1.Text = Image1.ImageUrl
End Sub
You forgot to save the file?
FileUpload1.SaveAs(string SomeFileNameOnServer) should happen too, before you display from the server.
(not sure how the above line is written in VB.NET)
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim path As String
path = Server.MapPath("~/.") + FileUpload1.FileName;
FileUpload1.SaveAs(path)
Image1.ImageUrl = path
Label1.Text = Image1.ImageUrl
End Sub
I'm trying to save an image to a local path (I'm not going to be deploying my project on a server) and I'm having difficulty with putting my finger on the correct path for the file upload:
Protected Sub htmleditorextender_ImageUploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs)
Dim fullpath = Request.MapPath("~/img/ar") & "/" & e.FileName
TextBox1_HtmlEditorExtender.AjaxFileUpload.SaveAs(fullpath)
e.PostedUrl = fullpath
End Sub
This doesn't work, and no image is uploaded to the said folder. What's going wrong?
try this
Protected Sub HTMLEditorExtender_ImageUploadComplete(sender As Object, e As AjaxControlToolkit.AjaxFileUploadEventArgs)
Dim fullpath As String = Server.MapPath("~/img/ar/") + e.FileName
HTMLEditorExtender.AjaxFileUpload.SaveAs(fullpath)
e.PostedUrl = Page.ResolveUrl(fullpath)
End Sub