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

//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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值