博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET 2.0中上传文件的简单实现
阅读量:4184 次
发布时间:2019-05-26

本文共 1579 字,大约阅读时间需要 5 分钟。

 

//file name: Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server"><title>无标题页</title></head>

<body>

    <h3>HtmlInputFile Example</h3>

 

    <form id="Form1" enctype="multipart/form-data" runat="server">

 

       Select File to Upload:

       <input id="File1" type="file" runat="server"/>

       <p>

       <span id="Span1" style="font: 8pt verdana;" runat="server" />

        </p>

       <p>

       <input type="button" id="Button1" value="Upload" onserverclick="Button1_Click" runat="server" />

       </p>

    </form>

</body>

</html>

 

//file name: Default.cs

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.IO;

 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

    }

    protected void Button1_Click(object sender, EventArgs e)

    {

        // Save the file.

        if (File1.PostedFile.ContentLength > 0)

        {

            string path = "";

            path = Page.MapPath(".");

            try

            {

                File1.PostedFile.SaveAs(path + "//msxml.exe");

                Span1.InnerHtml = "File uploaded successfully to <b>" + path + "//msxml.exe" + "</b> on the Web server.";

            }

            catch (Exception exc)

            {

                Span1.InnerHtml = "Error saving file <b>" + path + "//msxml.exe" + "</b><br>" + exc.ToString() + ".";

            }

        }

    }

}

转载地址:http://qhyoi.baihongyu.com/

你可能感兴趣的文章
scikit-learn
查看>>
原生java方法操作SQLite数据库
查看>>
sqlite 数据库驱动框架
查看>>
B树、B+树、B*树 总结
查看>>
kafka常用命令
查看>>
kafka顺序消息
查看>>
kafka 消息服务
查看>>
从零开始玩转JMX(一)——简介和Standard MBean
查看>>
究竟啥才是互联网架构中的高并发!
查看>>
数据库水平扩展与垂直扩展
查看>>
Jsp中include动作指令简介
查看>>
交互两个数(不引入第三个变量)
查看>>
C/C++面试题分享
查看>>
链表类型题目需要用到的头文件list.h
查看>>
tree类型题目需要用到的头文件tree.h
查看>>
有一个1亿结点的树,已知两个结点, 求它们的最低公共祖先!
查看>>
BST(binary search tree)类型题目需要用到的头文件binary_tree.h
查看>>
将BST转换为有序的双向链表!
查看>>
中体骏彩C++面试题
查看>>
永成科技C++笔试题
查看>>