且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何写图片网址路径?

更新时间:2023-11-27 20:55:58

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



  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...