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

  • 相关阅读:
    synchronized锁升级的过程(偏向锁到轻量锁再到重量级锁)转
    sprin 事务注解@Transactional的实现原理(转)
    springboot + redis + 注解 + 拦截器 实现接口幂等性校验(转)
    JAVA-TCP
    oracle查看连接信息
    C# 计算两个字符的相似度
    Java设计模式桥接模式
    C# Newtonsoft.Json.JsonReaderException:“Could not convert string to decimal:
    java设计模式结构型模式
    Java设计模式原型模式
  • 原文地址:https://www.cnblogs.com/cosiray/p/1551969.html
Copyright © 2011-2022 走看看