如何将图像 url 从 vb.net 传递到 asp.net?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16143829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pass image url from vb.net to asp.net?
提问by salathia
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
我正在从 vb.net 获取图像名称路径并希望将其传递给 asp.net 中的图像 URL .. 怎么做......我正在这样做但在 Vb.net 中什么也不显示
dim myLogo as string = ResolveUrl("C:\Test\Logo\" & img_name)
Me.DataBind()
IN ASP.net
在 ASP.net 中
<asp:Image ID="test" ImageUrl='<% myLogo %>' runat="server" Height="100px" Width="100px" />
回答by Kapil Khandelwal
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.
ASP.NET 包括 Web 应用程序根运算符 (~),您可以在服务器控件中指定路径时使用它。ASP.NET 将 ~ 运算符解析为当前应用程序的根。您可以将 ~ 运算符与文件夹结合使用来指定基于当前根目录的路径。
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.
下面的示例显示了在使用 Image 服务器控件时用于为图像指定根相对路径的 ~ 操作符在此示例中,从位于 Web 应用程序根目录下的 Images 文件夹中读取图像文件,无论页面在网站中的位置。
<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:
有关更多详细信息,请参阅:
Eg.
例如。
dim myLogo as string = "~\Logo\" & img_name
回答by Ravi
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.
您需要在代码的一般部分将 myLogo 变量声明为受保护,并且在 aspx 页面中,您可以使用以下代码来绑定 imageurl。
<asp:image runat="server" Height="100px" Width="100px" imageurl='<%#myLogo%>' />
Please let me know if this does not work.
如果这不起作用,请告诉我。
回答by Emad Mokhtar
Try this
尝试这个
<asp:Image ID="test" ImageUrl='<%= myLogo %>' runat="server" Height="100px" Width="100px" />
回答by Matt Wilko
Surely the url to the file will be:
当然,文件的 url 将是:
"file://c:\Test\Logo\" & img_name
Have you tried that?
你试过吗?

