ASP.NET文件上传 [英] ASP.NET File Upload

查看:142
本文介绍了ASP.NET文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使一个服务器页面(C#,asp.net 2.0 +),从另一页保存上传的文件。

I am trying to make a server page (C#, asp.net 2.0+) to save an uploaded file from another page.

具体地,
我有一个HTML页面

Specifically, I have an HTML page with a

<form action="upload.aspx"> 

和我无法弄清楚如何处理节省upload.aspx服务器上的文件。

and I can't figure out how to handle saving the file on the server in upload.aspx.

我发现了几个例子(的一个是:<一href=\"http://msdn.microsoft.com/en-us/library/aa479405.aspx\">http://msdn.microsoft.com/en-us/library/aa479405.aspx)
但是这需要在&LT;输入类型=文件&gt; 元素是相同的页面上。

I found a few examples (one being: http://msdn.microsoft.com/en-us/library/aa479405.aspx) but that requires the <input type=file> element to be on the same page.

我有抓住我的upload.aspx页面上发布的文件困难。

I am having difficulties with grabbing the posted file on my upload.aspx page.

任何人有任何指针?我怎样才能抢到一个ASPX发布文件并将其保存到服务器时,该文件从另一个网页贴?

Anyone have any pointers? How can I grab a posted file in aspx and save it to the server when the file is posted from another page?

非常感谢,
布雷特

Many thanks, Brett

推荐答案

1,创建Uploadfile.aspx

1.Create Uploadfile.aspx

利用IFRAME 2.Embed的Uploadfile.aspx在HTML页面

2.Embed the Uploadfile.aspx in Your Html page using iframe

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Uploadfile.aspx.cs" Inherits="Uploadfile" %>
    <!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>File Upload Control</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:FileUpload  runat="server" ID="fuSample" />
        <asp:Button  runat="server" ID="btnUpload" Text="Upload" 
                onclick="btnUpload_Click" />
                <asp:Label runat="server" ID="lblMessage" Text=""></asp:Label>
        </div>
        </form>
    </body>
    </html>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Uploadfile : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        //Files is folder Name
        fuSample.SaveAs(Server.MapPath("Files") + "//" + fuSample.FileName);
        lblMessage.Text = "File Successfully Uploaded";
    }
}

然后嵌入您的aspx页面在HTML如下,

then embed your aspx page in Html as follow,

<iframe height="40" width="700" src="Uploadfile.aspx">
</iframe>

现在你可以能够上传从HTML本身文件,通过使用UploadFiles.aspx。

now you can be able to upload your file from html itself,by using UploadFiles.aspx.

这篇关于ASP.NET文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆