资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

asp.net文件上传并显示文件名删除文件重新上传

          
前台页面:

活动/宣传信息



 
  
  
 
 
  
   
   
 
   
  
 
 
 
   
   
 
 
   
  
 
 
   
  
 
活动名称*
活动概要
  
   
活动时间段
活动地区
活动地点
宣传媒体

 

上传附件





 
       
            其他格式促销资料:                Width="300px" />
       

 
 
 





 
 
 
 
 



 
 
 
后台处理:
 //上传附件
        protected void lbUpload_Click(object sender, EventArgs e)
        {
            fileUpload();
        }
        //删除附件
        protected void delA_Click(object sender, CommandEventArgs e)
        {
            string path = fileUploadPath.Value;
            path = Server.MapPath(path);
            FileInfo file = new FileInfo(path);
            if (file.Exists)
            {
                file.Delete();
            }
            fileUploadPath.Value = "";
            fuPhoto.Visible = true;
            filePath.Visible = false;
            delA.Visible = false;
        }
        public void fileUpload()
        {
            if (fuPhoto.PostedFile != null && fuPhoto.PostedFile.ContentLength > 0)
            {
                string ext = System.IO.Path.GetExtension(fuPhoto.PostedFile.FileName).ToLower();
                //if (ext != ".jpg" && ext != ".jepg" && ext != ".bmp" && ext != ".gif" && ext != ".png")
                //{
                //    this.Alert("请上传(*.jpg,*.jepg,*.bmp,*.gif,*.png)格式的图片!");
                //    return;
                //}
                string dir = Server.MapPath(PRODUCE_TEMP_FILE_PATH);
                if (Directory.Exists(dir) == false)
                {
                    Directory.CreateDirectory(dir);
                }
                string filename = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ext;
                string path = PRODUCE_TEMP_FILE_PATH + filename;
                fuPhoto.PostedFile.SaveAs(Server.MapPath(path));
                fileUploadPath.Value = path;
                fuPhoto.Visible = false;
                delA.Visible = true;
                filePath.Visible = true;
                filePath.Text = fuPhoto.FileName;
                filePath.NavigateUrl = path;
                // uploadfilepath.Text = path;
            }
            else
            {
                //do some thing;
            }
        }
 
 
保存

            ProductSellPlanEntity sellplan = new ProductSellPlanEntity();
            sellplan.ResourceId = System.Guid.NewGuid().ToString();
            sellplan.ProjectId = productNum.Text;
            sellplan.CreateNumber = createNumber.Text;
            sellplan.ContantCompany = companyID.Value;
            sellplan.ProjectTime = projecttime.Text;
            sellplan.CreateUser = this.CurrentUser.UserName;
            sellplan.CreateUserID = CurrentUser.UserId;
            sellplan.Telphone = CurrentUser.OfficePhone;
            sellplan.ActivityName = activityname.Text;
            sellplan.ActivityDescription = summary.Text;
            sellplan.ActivityTime = time.Text;
            sellplan.ActivityArea = area.Text;
            sellplan.ActivityAddress = address.Text;
            sellplan.PropagandaMedia = media.Text;
            sellplan.UploadFilename = filePath.Text;
            if (!string.IsNullOrEmpty(fileUploadPath.Value))
            {
                string path = Server.MapPath(fileUploadPath.Value);
                FileInfo file = new FileInfo(path);
                if (file.Exists)
                {
                    string dir = Server.MapPath(PRODUCE_FILE_PATH);
                    if (Directory.Exists(dir) == false)
                    {
                        Directory.CreateDirectory(dir);
                    }
                    string fname = DateTime.Now.ToString("yyyyMMddHHmmssffff") + filePath.Text;
                    string targetFile = dir + fname;
                    if (path.IndexOf("ImportFiles") >= 0)
                    {
                        file.CopyTo(targetFile);
                    }
                    sellplan.UploadFilepath = PRODUCE_FILE_PATH + fname;
                }
                if (path.IndexOf("ImportFiles") >= 0)
                {
                    FileInfo filetemp = new FileInfo(path);
                    filetemp.Delete();
                }
            }
 
 
 
效果图片:asp.net文件上传并显示文件名删除文件重新上传

新闻名称:asp.net文件上传并显示文件名删除文件重新上传
地址分享:http://cdkjz.cn/article/ghecog.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220