ASP.net image.imageurl没有显示任何内容

时间:2011-10-16 11:23:19

标签: asp.net

我有一个服务器图像控件,id是Picoftheday,我试图为该图像控件生成一个URL。 这是我的图片网址生成代码.....

private string PicID()
    {
        DataTable dt = new DataTable();
        Connection dbconn = new Connection();
        SqlDataAdapter ad = new SqlDataAdapter();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "select top(1) picture_ID from t_picture order by Picture_UploadDate desc";
        ad.SelectCommand = cmd;
        cmd.Connection = dbconn.DBConnection;
        ad.Fill(dt);
        string value = null;
        foreach (DataRow dr in dt.Rows)
        {
            value = dr[0].ToString();

        }
        string url = Server.MapPath("..\\ArchievedPic\\Thumbnail\\");
        string[] files = Directory.GetFiles(@url, "" + value + ".*");
       // string url = files[0].ToString();
        string money = files[0].ToString();
        return money;
    }
页面加载时

....

protected void Page_Load(object sender, EventArgs e)
    {
        Picoftheday.ImageUrl = PicID();
    }

有人可以帮忙吗...

1 个答案:

答案 0 :(得分:1)

MapPath需要一个代表asp应用程序根目录的代字号:

string url = Server.MapPath("~\\ArchievedPic\\Thumbnail\\");