fileupload控件在修改的时候路径是否可以显示? 
//不明白

解决方案 »

  1.   

        protected void Button2_Click(object sender, EventArgs e)
        {
            if(UpLoadPic()) 
            {
                Response.Write(FileUpload1.PostedFile.FileName.ToString());
            }
        }private string[] AcceptedFileTypes = new string[] { "jpg", "jpeg", "jpe" ,"png","p2p"};    public bool UpLoadPic()//上传   
        {
            bool ifSucess = false;
            if (FileUpload1.PostedFile.ContentLength > 0)
            {
                if (IsValidFileType(FileUpload1.PostedFile.FileName))
                {                if (FileUpload1.PostedFile.ContentLength < 1024 * 2000)
                    {                    string fullName = FileUpload1.PostedFile.FileName;
                        string newName = System.DateTime.Now.ToString("yyyyMMddhhmmss") + fullName.Substring(fullName.LastIndexOf("."));
                        string path = Server.MapPath("UpLoad");
                        FileUpload1.SaveAs(path + "/" + newName);
                        Label1.Text = newName;
                        Image1.ImageUrl = "UpLoad/" + newName;
                        Image1.Visible = true;
                        ifSucess = true;
                    }
                    else
                    {
                        Response.Write("<script>alert('出错了!上传文件太大!')</script>");
                    }
                }
                else
                {
                    ifSucess = false;
                    Response.Write("<script>alert('出错了!上传文件格式不对!')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('出错了!上传文件不能为空!')</script>");
            }
            return ifSucess;
        }
        private bool IsValidFileType(string FileName)//图片格式检验   
        {
            string ext = FileName.Substring(FileName.LastIndexOf(".") + 1, FileName.Length - FileName.LastIndexOf(".") - 1);
            for (int i = 0; i < AcceptedFileTypes.Length; i++)
            {
                if (ext.ToLower() == AcceptedFileTypes[i])
                {
                    return true;
                }
            }
            return false;
        }
      

  2.   

    不能  这个控件的地址属性 是只读的  ,不可以赋值  你可以用一个label显示哪个地址啊