zoukankan      html  css  js  c++  java
  • asp.net图片上传


    代码
    protected void Button1_Click(object sender, EventArgs e)
        {
            
    string FilePath = Server.MapPath("./"+ "File";//将要存放的路径文件File;
            string newName;    
            
    string picExt;
            
    if (FileUpload1.HasFile)
            {
    //判断选择了文件

                HttpPostedFile HPF 
    = FileUpload1.PostedFile;
                
    // 这种方法用单个文件上传,多个文件要用HttpFileCollection

                
    if (HPF.ContentLength > 0)
                {
    //判断文件大小              
                    picExt = System.IO.Path.GetExtension(HPF.FileName).ToLower();//获得文件的拓展     
                    newName = DateTime.Now.ToString("yyyyMMddHHmmss");
                    newName 
    += picExt;
                    
    if (picExt==".jpg"||picExt==".bmp"||picExt==".png"||picExt==".gif")
                    {
                        
    // HPF.SaveAs(FilePath + "\\" + System.IO.Path.GetFileName(HPF.FileName));HPF.FileName这个是获取文件的名字
                        HPF.SaveAs(FilePath + "\\" + System.IO.Path.GetFileName(newName));
                    }
                    
    else
                    {
                        
    this.Label1.Text = "图片格式不支持,请选择jpg|png|gif|bmp格式";
                    }
                 
                }
                      
            }
            
    else
            {
                Label1.Text 
    = "请选择图片";        
            }
            
        }
     
  • 相关阅读:
    【iOS开发】协议与委托 (Protocol and Delegate) 实例解析(转)
    Axure例——双击显示
    联动下拉菜单应用
    VB 9.0 和C# 3.0比较
    Office VBA进阶(二):如何在Access 2007里导入一个Excel sheet表
    Static Code Analysis Introduction
    VB future
    Office VBA进阶(三):如何合并Access里的多张表
    Office VBA进阶(四):如何在Access里创建一个Report
    Office VBA进阶(五):如何让EXCEL工作簿在浏览器里显示
  • 原文地址:https://www.cnblogs.com/clc2008/p/1613411.html
Copyright © 2011-2022 走看看