0

I m fetching the image name path from vb.net and want to pass it to image URL in asp.net.. How to do... I m doing this but display nothing IN Vb.net

dim myLogo as string = ResolveUrl("C:\Test\Logo\" & img_name)
Me.DataBind()

IN ASP.net

<asp:Image ID="test" ImageUrl='<% myLogo %>' runat="server" Height="100px" Width="100px" />

4 Answers 4

2

ASP.NET includes the Web application root operator (~), which you can use when specifying a path in server controls. ASP.NET resolves the ~ operator to the root of the current application. You can use the ~ operator in conjunction with folders to specify a path that is based on the current root.

The following example shows the ~ operator used to specify a root-relative path for an image when using the Image server control In this example, the image file is read from the Images folder that is located directly under the root of the Web application, regardless of where in the Web site the page is located.

<asp:image runat="server" id="Image1"
  ImageUrl="~/Images/SampleImage.jpg" />

You can use the ~ operator in any path-related property in server controls. The ~ operator is recognized only for server controls and in server code. You cannot use the ~ operator for client elements.

For more details refer:

ASP.NET Web Project Paths

Eg.

dim myLogo as string = "~\Logo\" & img_name
Sign up to request clarification or add additional context in comments.

Comments

0

Surely the url to the file will be:

"file://c:\Test\Logo\" & img_name

Have you tried that?

Comments

0

Try this

<asp:Image ID="test" ImageUrl='<%= myLogo %>' runat="server" Height="100px" Width="100px" />

Comments

0

You need to declare myLogo variable as protected in general section of code and in aspx page you can use folling code to bind imageurl.

<asp:image runat="server" Height="100px" Width="100px" imageurl='<%#myLogo%>' />

Please let me know if this does not work.

2 Comments

This will work only if the Image control located inside DataBound control
This is not always necessary. we can bind page control with variables. salathia already called me.databind so we can bind image url with variable myLogo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.