.net中的FINDCONTROL和创建文件夹,保存文件

来源:互联网 发布:天猫隐形眼镜 知乎 编辑:程序博客网 时间:2024/04/28 22:13

//GLOAL为自定义APPCODE类

查找PAGE的CONTROL

            HtmlForm form = (HtmlForm)this.Master.FindControl("form1");
            ContentPlaceHolder CP = (ContentPlaceHolder)form.FindControl("ContentPlaceHolder1");
            for (int i = 0; i < 4; i++)
            {
                string CName = "_fuFile" + Convert.ToString(i + 1);
                FileUpload FU = (FileUpload)CP.FindControl(CName);
                if (FU.HasFile)
                {
                    string FName = FU.FileName;
                    FU.PostedFile.SaveAs(Server.MapPath(Global.ApplicationPath + "/onlineprint_upload" + "/" + DateTime.Now.ToString("yyyyMMdd") + "/" + userid + "/" + FName));
                }
            }
查找用户控件中的CONTROL 直接用THIS.FINDCONTROL

查找REPEATER中的,要对应ITEM[I].findcontrol

查找GRIDVIEW 要对应ROW[I].CELL[I].CONTROL[I];

另外 创建文件夹和保存文件

            string userid = Convert.ToString(Session["ComUserId"]);
            string dir = Server.MapPath(Global.ApplicationPath + "/onlineprint_upload" + "/" + DateTime.Now.ToString("yyyyMMdd") + "/" + userid);
            System.IO.Directory.CreateDirectory(dir);
            HtmlForm form = (HtmlForm)this.Master.FindControl("form1");
            ContentPlaceHolder CP = (ContentPlaceHolder)form.FindControl("ContentPlaceHolder1");
            for (int i = 0; i < 4; i++)
            {
                string CName = "_fuFile" + Convert.ToString(i + 1);
                FileUpload FU = (FileUpload)CP.FindControl(CName);
                if (FU.HasFile)
                {
                    string FName = FU.FileName;
                    FU.PostedFile.SaveAs(Server.MapPath(Global.ApplicationPath + "/onlineprint_upload" + "/" + DateTime.Now.ToString("yyyyMMdd") + "/" + userid + "/" + FName));
                }
            }

 

 

 

        HtmlForm form = (HtmlForm)this.Master.FindControl("form1");
        ContentPlaceHolder CP = (ContentPlaceHolder)form.FindControl("ContentPlaceHolder1");

        UserControl Rent_Info = (UserControl)CP.FindControl("Rent_Info1");
        Label _lb = (Label)Rent_Info.FindControl("_lbDistrict");
        _lbTitle.Text = _lb.Text;