上传文件实现多选
可以获取文件信息入库 实在没时间了,本人水平一般,希望源码,! 谢谢了!
可以获取文件信息入库 实在没时间了,本人水平一般,希望源码,! 谢谢了!
解决方案 »
- jj2是什么类?有什么作用?
- vs2005调试问题及解决方案锦集
- 关于xml架构的问题
- 高分求助:用C#写个简单的Client,Server聊天程序 急急...
- 有关.net WEb开发中dropdownList控件的一个问题!谢谢
- VS左边工作区打开文档和右边资源管理器中选中文档不同步问题
- 新手上路!!!!
- 小弟求助把swf文件输入到浏览器出现乱码的现象
- asp.net 中服务器组件有没有类似于HTML中的file组件?(用来上传东西的)
- HyperLink控件的navigateurl是否可以传参数?
- 404错误解决方法~本机测试没错~IIS上有错误~
- ImageButtom中的imageUrl中,用了字符串加变量就会输出HTML编码来,<%=aa>显示不出来
http://www.cnblogs.com/Dragon-China/archive/2007/07/13/817393.html
http://www.cnblogs.com/homer/archive/2008/01/04/1025984.html
http://www.cnblogs.com/Fooo/archive/2006/11/07/553104.html
http://www.cnblogs.com/wengjinbao/archive/2007/06/19/788639.html
希望能给份!
肯定有楼主需要的
仔细看demo,里面有multiple上传的。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UpLoad.aspx.cs" Inherits="UpLoad" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<head>
<title>多文件上传</title>
<script type="text/javascript" language="javascript">
function addFile()
{
var str = '<INPUT type="file" size="50" NAME="File" ></br>' ;
document.getElementById('MyFile').insertAdjacentHTML("beforeEnd",str);
} function forReset()
{
var files=document.getElementsByName("File");
for(var j=0; j<files.length; j++)
{
files[j].outerHTML=files[j].outerHTML.replace(/value=\w/g,'');
}
}
</script>
</head>
<body>
<form id="form1" method="post" runat="server" enctype="multipart/form-data">
<div align="center">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div>
<p>
<asp:TextBox runat="server" ID="txtName"></asp:TextBox>
</p>
<p>
<asp:DropDownList ID="ddlAction" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlAction_SelectedIndexChanged" >
<asp:ListItem Value="true"></asp:ListItem>
<asp:ListItem Value="false"></asp:ListItem></asp:DropDownList>
</p>
<p>
<asp:RadioButton ID="radYes" runat="server" GroupName="groupName1"/>
<asp:RadioButton ID="radNo" runat="server" GroupName="groupName1"/>
</p>
</div>
<div>
<p id="MyFile"><input type="file" size="50" name="File" /><br/></p>
<p>
<input type="button" value="增加(Add)" onclick="addFile()"/>
<input onclick="forReset()" type="button" value="重置(ReSet)"/>
<asp:Button Runat="server" Text="开始上传" ID="UploadButton"></asp:Button>
</p>
<p>
<asp:Label id="strStatus" runat="server" Font-Names="宋体" Font-Bold="True" Font-Size="9pt"
Width="500px" BorderStyle="None" BorderColor="White"></asp:Label>
</p>
<p>
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
</p>
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="UploadButton" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html> using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;public partial class UpLoad : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
radNo.Checked = true;
this.SaveImages();
ddlAction_SelectedIndexChanged(sender, e);
}
} private Boolean SaveImages()
{
///'遍历File表单元素
HttpFileCollection files = HttpContext.Current.Request.Files; /// '状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
strMsg.Append("上传的文件分别是:<hr color=red>");
try
{
for (int iFile = 0; iFile < files.Count; iFile++)
{
///'检查文件扩展名字
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if (fileName != "")
{
fileExtension = System.IO.Path.GetExtension(fileName);
strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("上传文件的文件名:" + fileName + "<br>");
strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>");
///'可根据扩展名字的不同保存到不同的文件夹
///注意:可能要修改你的文件夹的匿名写入权限。
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch (System.Exception Ex)
{
strStatus.Text = Ex.Message;
return false;
}
} protected void ddlAction_SelectedIndexChanged(object sender, EventArgs e)
{
radYes.Checked = System.Convert.ToBoolean(ddlAction.SelectedItem.Value);
radNo.Checked = !(radYes.Checked);
txtName.Text = ddlAction.SelectedItem.Value;
}
}
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;namespace WebApplication1
{
public partial class uploadDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } protected void btnUpload_Click(object sender, EventArgs e)
{
HttpFileCollection fileToUpload = Request.Files;
foreach (string keyName in fileToUpload.AllKeys)
{
HttpPostedFile file = fileToUpload[keyName];
if (file.FileName == string.Empty)
return;
try
{
string path = Server.MapPath("Images") + @"\" + Path.GetFileName(file.FileName);
using (FileStream writer = new FileStream(path, FileMode.Create, FileAccess.Write))
{
int bufferSize = 4096 * 10;
byte[] buffer = new byte[bufferSize];
int len = 1;
while (len != 0)
{
len = file.InputStream.Read(buffer, 0, bufferSize);
writer.Write(buffer, 0, len);
}
}
}
catch
{
throw new Exception();
}
}
}
}
}
=========================================================================================
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="uploadDemo.aspx.cs" Inherits="WebApplication1.uploadDemo" %><!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>Upload Page</title> <script type="text/javascript">
function $(id)
{
return document.getElementById(id);
}
function stripPath(name)
{
var pieces = name.split("\\");
return pieces[pieces.length-1];
} function uploadfileOperator(n)
{
var currentFile = $('file' + n);
var newFile = document.createElement('input');
newFile.id = 'file' + (n + 1);
newFile.name = 'file' + (n + 1);
newFile.type = 'file';
newFile.size = currentFile.size;
newFile.onchange = function(){uploadfileOperator(n + 1);}
var newItem = document.createElement('option');
newItem.value = stripPath(currentFile.value);
newItem.id = 'item' + n;
newItem.name = 'item' + n;
newItem.appendChild(document.createTextNode(currentFile.value));
$('sellist').appendChild(newItem);
currentFile.style.display = 'none';
$('fileFolder').appendChild(newFile);
}
</script></head>
<body>
<form id="form1" runat="server" enctype="multipart/form-data">
<div id="dvupload">
<span id="fileFolder">
<input type="file" onchange="uploadfileOperator(0)" id="file0" name="file0" />
</span>
</div>
<div id="dvlist">
<select id="sellist" style="width:100px" size="6">
</select>
</div>
<div>
<asp:Button ID="btnUpload" Text="UpLoad" runat="server" onclick="btnUpload_Click" />
</div>
</form>
</body>
</html>
=========================================================
microsoft function