ASP.NET实现文件上传!(100分,放送!)
ASP.NET只点击一个按钮实现文件上传,我不想用 <input type =file> .
我想只点一个键弹窗口,选文件确定后上传,就和QQ那样。。
------解决方案--------------------点按钮,用js,window.open一个窗口,这个新的窗口里面在用 <input type=file>
------解决方案--------------------在ASP.NET中不是有空间FileUpload吗?
这个就可以实现啊~
------解决方案--------------------WEB页面里上传文件,最后生成的HTML里都是有 <input type =file> 这个的.
你可以用JavaScript来简化用户的操作,当用户点按钮时,模拟用户点击了 <input type =file> ,在用户选择好文件后,就可以上传文件,只要给 <input type =file> 添加一个事件就可以处理了.
------解决方案--------------------VS2005 FileUpLoad
------解决方案--------------------FileUpLoad
------解决方案--------------------最终还是file,想不出什么
------解决方案--------------------用2.0自带的上传控件,在你工程中建好要上传的文件夹
C#:
---------------------------
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 oneup : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//点击上传按钮
protected void cmdbtn_Click(object sender, EventArgs e)
{
string name = this.FileUpload1.FileName;//获取已上传的文件名
string size = this.FileUpload1.PostedFile.ContentLength.ToString();//获取已上传文件的大小
string type = this.FileUpload1.PostedFile.ContentType;//获取已上传文件的MIME内容类型
string type2 = name.Substring(name.LastIndexOf( ". ") + 1);//获取文件的后缀名
string path = Server.MapPath( "~/file/ "+name);//获取上传的实际路径
string dbpath = "file\\ " + name;//写到库里的虚拟路径
this.FileUpload1.SaveAs(path);//将文件保存到path这个路径里
}
}
-----------------------------
HTML:
<html xmlns= "http://www.w3.org/1999/xhtml " >
<head runat= "server ">
<title> 单文件上传 </title>
</head>
<body>
<form id= "form1 " runat= "server ">
<div>
<table style= "left: 190px; width: 361px; position: relative; top: 75px ">
<tr>
<td align= "center " colspan= "3 ">
<asp:Label ID= "Label1 " runat= "server " Font-Bold= "True " ForeColor= "#C00000 " Style= "position: relative "
Text= "单个文件上传 "> </asp:Label> </td>
</tr>
<tr>
<td align= "center " colspan= "3 ">
<asp:FileUpload ID= "FileUpload1 " runat= "server " Style= "position: relative " /> </td>
</tr>
<tr>
<td align= "center " colspan= "3 ">
<asp:Button ID= "cmdbtn " runat= "server " OnClick= "cmdbtn_Click " Style= "position: relative "