注册 登录
编程论坛 ASP.NET技术论坛

上传文件出现错误提示

yeyuanzhi 发布于 2008-08-09 15:59, 890 次点击
upload.cs源码如下:
 public string Up(System.Web.UI.HtmlControls.HtmlInputFile File2, string Pa)
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //

        if (File2.PostedFile.ContentLength.ToString() == "0")
        {
            return "0";
        }
        else
        {
            //获取文件名称
            string ss;
            ss = System.DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + Path.GetExtension(File2.PostedFile.FileName);
            if (File2.PostedFile.ContentLength / 1024 > 10)
            { return "1"; }
            else
            {
                string ty = File2.PostedFile.ContentType;
                if (ty == "image/gif" || ty == "image/pjpeg")
                {
                    File2.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath(Pa) + ss);
                    s = "../Uploads/" + ss;
                    return "3";
                    //Up= ss;
                }
                else
                { return "2"; }
            }
        }

    }
然后在网页后台调用代码如下:
protected void Button1_Click(object sender, EventArgs e)
    {
        string res;
        upload up = new upload();
        res = up.Up(file1, "Uploads/");
            }
运行提示:
未能找到路径“D:\kjweb\admin\Uploads\200889155047.jpg”的一部分。
是什么原因,怎么解决?谢谢!!
1 回复
#2
雪雨星风2008-08-11 09:46
你用相对路径试试
1