简体   繁体   English

如何将图像URL设置为绝对物理路径?

[英]how to set image URL as absolute physical path?

i have image-button control in a grid view my customer need to enter a path of folder in another page i stored this path in database i need because customer store images in external hard cannot transfer image from hard disk to website images because it has a huge size 我在网格视图中有图像按钮控制我的客户需要在另一个页面中输入文件夹的路径我将此路径存储在数据库中我需要因为外部硬盘中的客户存储图像无法将图像从硬盘传输到网站图像,因为它有一个巨大的

my image table contain image-name when user display grid-view i concatenate image-name from database and path from database also how can i do that 我的图像表包含用户显示网格视图时的图像名称我从数据库连接图像名称和数据库中的路径也是如何做到的

            <asp:TemplateField HeaderText="photo">
           <ItemTemplate >


               <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# GetImagePath()+Eval("ImageName")  %>'  Width="100px" Height="100px" Style="cursor: pointer" OnClientClick = "return LoadDiv(this.src);" /> 
           </ItemTemplate>
           </asp:TemplateField>

you need write down in you function like this 你需要写下你这样的功能

public string GetImage(string name)
{
  string path = Path.Combine(Server.MapPath(("~/Admin/Images/" , name)); 
  return path;
}

or 要么

you can also do like this 你也可以这样做

void GrdVw_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        Image rowImage = (Image) e.Row.FindControl("currentDocFile");
        rowImage.ImageUrl = whatever;
    }
}

I suggest pass the image name as parameter to GetImagePath Try this: 我建议将图像名称作为参数传递给GetImagePath试试这个:

public string GetImagePath(string imageName)
{
   return VirtualPathUtility.ToAbsolute("~/images/" + imageName);
}

VirtualPathUtility.ToAbsolute(string) converts a virtual path to an application absolute path. VirtualPathUtility.ToAbsolute(string)将虚拟路径转换为应用程序绝对路径。 So you will get something like "/images/yourimage.jpg". 所以你会得到类似“/images/yourimage.jpg”的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM