如何写图片网址路径? [英] How to write image url path ?

查看:101
本文介绍了如何写图片网址路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在数据库中存储路径时,它存储在 D:\ OrgWebsite \ Traditional Day 2012 \Images\DSC01049.JPG 格式中。



但是在检索时我是否使用图像按钮

< asp:ImageButton ID =ImageButton1runat =serverCommandArgument ='<%#Eval(a_id )%>'ImageUrl ='<%#Eval(i_path)%>'高度=100宽度=100/>



它告诉我这个D:\\OrgWebsite \\ Traditional Day 2012 \\Images\\DSC01049.JPG格式。



所以我无法查看图像。

你可以帮忙吗?

解决方案

你必须通过编写这段代码将文件保存在该文件夹中:



  if (FileUpload1.HasFile ==  true 
{

// 将图像保存在文件夹中的代码
FileUpload1.SaveAs(Server.MapPath( 〜/ Traditional Day 2012 / Images / + FileUpload1.FileName));


// 将图像网址保存在数据库中的代码
string ImageUrl = 〜/ 2012年传统日/ Images / + FileUpload1.FileName;

}





然后你只需要在你的ImageButton控件中绑定该URL .... / blockquote>

保存在数据库中时,你应该只保存Images \DSC01049.JPG

i hope 图像将位于 root 目录中..

图像应仅在托管目录中..除此之外...

试一试。它应该工作......


when i am storing path in database its stores in D:\OrgWebsite\Traditional Day 2012\Images\DSC01049.JPG format.

but at time of retrieving if i use image button
<asp:ImageButton ID="ImageButton1" runat="server" CommandArgument='<%#Eval("a_id") %>' ImageUrl='<%#Eval("i_path") %>' Height="100" Width="100" />

it shows me this "D:\\OrgWebsite\\Traditional Day 2012\\Images\\DSC01049.JPG" format.

so i am unable to view images.
Can u help?

解决方案

You have to save your file at that folder by writing this code :

if (FileUpload1.HasFile == true)
        {
            
         //Code to save image in folder
            FileUpload1.SaveAs(Server.MapPath("~/Traditional Day 2012/Images/" + FileUpload1.FileName));


         //Code to save image url in database
            string ImageUrl = "~/Traditional Day 2012/Images/" + FileUpload1.FileName;

        }



And then You just have to bind that url in your ImageButton Control....


while saving in the database you should save only "Images\DSC01049.JPG"
i hope Images will be in the root directory..
Images should be in the hosted directory only.. not apart from that...
Try this. it should work...


这篇关于如何写图片网址路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆