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

  • 相关阅读:
    Cocos2D学习笔记(1)- 常用的类
    C++头文件的重复定义错误处理
    python3中的sort和sorted函数
    numpy提供的快速的元素级数组函数
    HDU 1180 诡异的楼梯(BFS)
    POJ 1020 Anniversary Cake(DFS)
    POJ 1564 Sum It Up(DFS)
    POJ 1190 生日蛋糕(DFS)
    HDU 1026 Ignatius and the Princess I(BFS+优先队列)
    HDU 1172 猜数字(DFS)
  • 原文地址:https://www.cnblogs.com/cosiray/p/1551969.html
Copyright © 2011-2022 走看看