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 = "你还没有选择上传文件!";
                }
            }
        }
    }
    
  • 相关阅读:
    矩形覆盖
    跳台阶与变态跳台阶
    有几个PAT【*】
    找零钱
    有理数的四则运算
    旧键盘打字
    查验身份证
    完美数列【置顶】
    旧键盘
    超简单webservice实例
  • 原文地址:https://www.cnblogs.com/hulang/p/2041021.html
Copyright © 2011-2022 走看看