zoukankan      html  css  js  c++  java
  • DetailsView结合fileupload的使用

    protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            string strPathSave;
            string strFileName;

            FileUpload f = (FileUpload)DetailsView1.FindControl("FileUpload1");

            //FileUpload1控件是否有上传的文件
            if (f.HasFile)
            {
                //取得文件上传后的完整路径和新的文件名称
                strFileName = f.FileName;
                strPathSave = Server.MapPath("/Images/StorePic/");
                strPathSave = strPathSave + System.DateTime.Now.ToString("yyyyMMddhhmmss") + strFileName.Substring(strFileName.LastIndexOf("."));

                //PostedFile对象也具有一个FileName属性,但是表示的是上传文件的全路径名,需要手工提取文件名
                f.SaveAs(strPathSave);

                //手工绑定,指定参数的默认值
                this.SqlDataSource1.InsertParameters["STOREPIC"].DefaultValue = strFileName;

                ////文件夹不存在的时候,创建文件夹
                //if (!System.IO.Directory.Exists(Server.MapPath(strUpPath)))
                //{
                //     System.IO.Directory.CreateDirectory(Server.MapPath(strUpPath));
                //}
            }
        }

        protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            string strPathSave;
            string strFileName;

            FileUpload f = (FileUpload)DetailsView1.FindControl("FileUpload1");

            //FileUpload1控件是否有上传的文件
            if (f.HasFile)
            {
                //取得文件上传后的完整路径和新的文件名称
                strFileName = f.FileName;
                strPathSave = Server.MapPath("/Images/StorePic/");
                strPathSave = strPathSave + System.DateTime.Now.ToString("yyyyMMddhhmmss") + strFileName.Substring(strFileName.LastIndexOf("."));

                //PostedFile对象也具有一个FileName属性,但是表示的是上传文件的全路径名,需要手工提取文件名
                f.SaveAs(strPathSave);

                //手工绑定,指定参数的默认值
                this.SqlDataSource1.InsertParameters["STOREPIC"].DefaultValue = strPathSave;

                ////文件夹不存在的时候,创建文件夹
                //if (!System.IO.Directory.Exists(Server.MapPath(strUpPath)))
                //{
                //     System.IO.Directory.CreateDirectory(Server.MapPath(strUpPath));
                //}
            }
        }

  • 相关阅读:
    使用element-ui组件el-table时需要修改某一行样式(包含解决样式无效的问题)或某一列的样式
    面试题:线程A打印1-10数字,打印到第5个数字时,通知线程B
    面试题:不使用数学库求平方根
    Springboot2.x集成Redis集群模式
    Springboot2.x集成Redis哨兵模式
    Springboot2.x集成单节点Redis
    基本算法:冒泡排序算法
    Redis进阶:Redis的哨兵模式搭建
    Redis进阶:Redis的主从复制机制
    Redis的消息订阅及发布及事务机制
  • 原文地址:https://www.cnblogs.com/cosiray/p/1551969.html
Copyright © 2011-2022 走看看