zoukankan      html  css  js  c++  java
  • ASP.NET基本控件FileUpload上传控件

    前台代码:

    <asp:FileUpload ID="FileUpload" runat="server" />
    <asp:Button ID="BtnUp" runat="server" onclick="BtnUp_Click" Text="上 传" />
    <asp:Label ID="LabMsg" runat="server"></asp:Label>
    


    后台代码:

    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    namespace docnet
    {
        public partial class up : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void BtnUp_Click(object sender, EventArgs e)
            {
                if (FileUpload.HasFile)
                {
                    string savePath = Server.MapPath("~/upload/");//指定上传文件在服务器上的保存路径
                    //检查服务器上是否存在这个物理路径,如果不存在则创建
                    if (!System.IO.Directory.Exists(savePath))
                    {
                        System.IO.Directory.CreateDirectory(savePath);
                    }
                    savePath = savePath + "\\" + FileUpload.FileName;
                    FileUpload.SaveAs(savePath);
                    LabMsg.Text = string.Format("<a href='upload/{0}'>upload/{0}</a>", FileUpload.FileName);
                }
                else
                {
                    LabMsg.Text = "你还没有选择上传文件!";
                }
            }
        }
    }
    
  • 相关阅读:
    Shell编程—用户输入
    Shell编程—结构化命令
    Shell编程—基础脚本
    跳表
    分布式项目——电商秒杀
    Dubbo详解
    Kafka工作流程
    Kafka内部实现原理
    Zk实现分布式锁
    Leetcode::Pathsum & Pathsum II
  • 原文地址:https://www.cnblogs.com/hulang/p/2041021.html
Copyright © 2011-2022 走看看