首页 新闻 会员 周边

asp.net关于路径的问题

0
悬赏园豆:5 [已关闭问题] 关闭于 2012-05-22 19:58

这是我自定义的一个ascx文件

<%@ Control Language="C#" ClassName="ShowImage" %>

<script runat="server">
    private string _filePath;
    public String FilePath
    {
        set
        {
            _filePath = value;
        }
        get
        {
            return _filePath;
        }
    }
    void Page_Load()
    {
        string imageName = GetRandomImage();
        Image1.ImageUrl = System.IO.Path.Combine(_filePath,imageName);
        Label1.Text = imageName;
    }
    private string GetRandomImage()
    {
        string[] images = System.IO.Directory.GetFiles(_filePath, "*.jpg");
        Random rn = new Random();
        return System.IO.Path.GetFileName(images[rn.Next(images.Length)]);
    }
</script>
<asp:Image runat="server" /><br />
<asp:Label runat="server" Text="Label"></asp:Label>

当给FilePath赋值的时候,赋一个物理路径,两者combine的结果却是D:/liu\\123.jpg

这是什么原因?怎么改进?

微澜的主页 微澜 | 初学一级 | 园豆:-1
提问于:2012-05-14 19:43
< >
分享
所有回答(1)
0

_imageFolderPath在哪儿?图片在保存时用物理路径,在网页上显示时用相对路径

artwl | 园豆:16736 (专家六级) | 2012-05-15 08:10

第一次写的时候有错误,应该是给FilePath赋值

支持(0) 反对(0) 微澜 | 园豆:-1 (初学一级) | 2012-05-15 10:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册