• ASP.NE 上传文件控件


     protected void Button1_Click(object sender, EventArgs e)
        {
            //if (Request["id"]==null && Request["id"]=="")
            //{
            //    Response.Write(Request["id"]);
            //}
            
            //return;
            if (this.FileUpload1.HasFile) //判断控件是否有值
            {
                string fileNameA = Path.GetExtension(this.FileUpload1.FileName); // .bmp
                //--
                string fileNameNo = Path.GetFileName(FileUpload1.PostedFile.FileName); //获取文件名和扩展名 //2017-11-24_110128.bmp
                string DirectoryName = Path.GetDirectoryName(FileUpload1.PostedFile.FileName); //获取文件所在目录  //""
                string Extension = Path.GetExtension(FileUpload1.PostedFile.FileName); //获取扩展名  //.bmp
                string fileName = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName); //获取文件名(不包括扩展名)  //2017-11-24_110128
                string fullPath = Path.GetFullPath(FileUpload1.PostedFile.FileName); //获取文件的绝对路径  //C:Program Files (x86)IIS Express2017-11-24_110128.bmp
                string PathRoot = Path.GetPathRoot(FileUpload1.PostedFile.FileName); //获取文件所在地分区 //""
                //--
                string path = Server.MapPath("upload/"); //C:UsersAdministratorDesktop后台练习后台练习sysupload
                //在上传的同时重命名
                this.FileUpload1.SaveAs(path+Guid.NewGuid()+fileName); //另存为文件
                Response.Write("上传成功!");
    
            }
            else
            {
                Response.Write("请选择文件");
            }
        }

    <div>
    <asp:FileUpload ID="FileUpload1" runat="server" />

    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="上传" />
    </div>

  • 相关阅读:
    SQL 索引
    SQL 存储
    C#编程中的66个好习惯,你有多少个?
    Delphi中如何让窗口最小化至系统托盘
    浅谈 堆和堆栈
    C#编程中的66个好习惯
    用ADO连接oracle的步骤
    如何卸载ocx包
    数据库中,Decimal数据类型
    [转载]内存区划分、内存分配、常量存储区、堆、栈、自由存储区、全局区
  • 原文地址:https://www.cnblogs.com/enych/p/7890082.html
Copyright © 2020-2023  润新知