本文共 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/