求批量上传工具,或 思路 主要上传 声音文件, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果单个文件不大,则使用ASP.NET自带的组件就好了..如果文件过大..使用FTP类.单独写上传...尽量考虑一下,上传的文件个数 * 单个文件大小 = 总大小 < 300M 我做的上传单个文件:上传按钮事件:{string fname,path;fname=System.IO.Path.GetFileName(filMyFile.Value.ToString()); //获得要上传的文件的文件名(文件名带扩展名) filMyFile.Value 是上传文件的路径path=DBCon.mp3UploadString()+ddlmPath.SelectedItem.Text; //上传路径HttpPostedFile myFile = filMyFile.PostedFile; // 获得一个postedfileint nFileLen = myFile.ContentLength; // 上传文件的长度byte[] myData = new byte[nFileLen]; // 转换为字节流myFile.InputStream.Read(myData,0,nFileLen);string Mpath=Server.MapPath("//"); //服务器物理路径 路径要自己定义string Mpath2=Mpath+fname;WriteToFile(Mpath2,ref myData); //保存文件 }private void WriteToFile(string strPath, ref byte[] Buffer){ // 创建一个文件 FileStream newFile = new FileStream(strPath, FileMode.Create); // 读文件 newFile.Write(Buffer,0,Buffer.Length); // 关闭文件 newFile.Close();} 前台<%@ Page language="c#" Codebehind="upMoreFile.aspx.cs" AutoEventWireup="false" Inherits="CommonFunction.upMoreFile" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML><HEAD><title>upMoreFile</title><meta content="Microsoft Visual Studio 7.0" name="GENERATOR"><meta content="C#" name="CODE_LANGUAGE"><meta content="JavaScript" name="vs_defaultClientScript"><meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"><script language="JavaScript">function addFileControl(){var str = '<INPUT type="file" NAME="File">'document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str)}</script></HEAD><body MS_POSITIONING="GridLayout"><form id="upMoreFile" method="post" encType="multipart/form-data" runat="server"><asp:label id="Title" Runat="server"></asp:label><P id="FileCollection"><INPUT type="file" name="File"></P><P><input onclick="addFileControl()" type="button" value="增加(File)"><asp:button id="Upload" Runat="server" Text="上传" Width="56px"></asp:button><input style="WIDTH: 56px; HEIGHT: 24px" onclick="this.form.reset()" type="button" value="重置"></P><P align="center"><asp:label id="strStatus" runat="server" BorderColor="White" BorderStyle="None" Width="500px"Font-Size="9pt" Font-Bold="True" Font-Names="宋体"></asp:label></P></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;namespace CommonFunction{/// <summary>/// upMoreFile 的摘要说明。/// </summary>public class upMoreFile : System.Web.UI.Page{protected System.Web.UI.WebControls.Button Upload;protected System.Web.UI.WebControls.Label Title;protected System.Web.UI.WebControls.Label strStatus;private void Page_Load(object sender, System.EventArgs e){Title.Text = "<h3>多文件上传</h3>";Upload.Text = "开始上传";}#region Web Form Designer generated codeoverride protected void OnInit(EventArgs e){//// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。//InitializeComponent();base.OnInit(e);}/// <summary>/// 设计器支持所需的方法 - 不要使用代码编辑器修改/// 此方法的内容。/// </summary>private void InitializeComponent(){ this.Upload.Click += new System.EventHandler(this.Upload_Click);this.Load += new System.EventHandler(this.Page_Load);}#endregionprivate void Upload_Click(object sender, System.EventArgs e){upMorefile();}private bool upMorefile(){//遍历File表单元素System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;//状态信息System.Text.StringBuilder strMsg = new System.Text.StringBuilder("上传的文件信息分别为:<hr color=red>");int fileCount;int filecount = files.Count;try{for(fileCount = 0;fileCount<files.Count;fileCount++){//定义访问客户端上传文件的对象System.Web.HttpPostedFile postedFile = files[fileCount];string fileName, fileExtension;//取得上传得文件名fileName = System.IO.Path.GetFileName(postedFile.FileName);if(fileName != String.Empty){//取得文件的扩展名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 color=red>");//保存到指定的文件夹postedFile.SaveAs(Server.MapPath("upedFile/") + fileName);}}strStatus.Text = strMsg.ToString();return true;}catch(System.Exception error){strStatus.Text = error.Message;return false;}}}}转 csdn上的一位兄弟 客户端用ocx,服务器端用web service 谢谢大家的参与,这两天我试了好多方法 包括上面 luby(轻疯 [就让这一切随疯而去吧,随风而去吧。]) 的, 对不错,但对于我的问题,还是不方便,我详细说一下 要实现的功能, 请各位高手指点,我要实现的是,从本地计算机的某个文件夹中取出 数据(数据量很大,文件个数很多。 文件个数*单个文件大小 >> 几十G ) 然后上传的服务器上的某个文件夹中,谢谢 这样还是用FTP比较好,为什么要用Web呢?Web就是为了大众化——只要有浏览器就可以用,并且简单易用。但显然你的需求所要实现的不会是大众化的吧?最多就是管理员会这样做,为什么一定要用Web实现呢? 如果是这样的话,我还是会选择FTP上传,然后在Web上面做有关数据库的操作,我会这样设计这个东西:(假设确实只有管理员用这种上传功能)1.管理员登录到Web管理界面,点击“准备从FTP上传”,这时候生成一个临时FTP上传帐号(例如你用Serv-U做FTP,用SQL Server做Serv-U的用户数据库,那就相当于向数据库添加一条记录而已),该临时上传帐号的根目录绑定到一个临时目录。2.管理员通过FTP上传文件。3.管理员在Web管理界面选择“此次上传结束”,此时该临时FTP上传帐号被删除,那么该临时上传目录应该就没有人有写权限的了。接着,程序就可以递归遍历该临时上传目录,把音乐文件复制到真正的音乐存放目录,同时进行重命名和记录到数据库的操作。整个复制和记录工作完成后,删除该临时上传目录。这样的好处就是既实现了FTP,而且每个上传过程都是独立的不会相互干扰的,不会发生任何读写冲突。如果两个管理员同时要求上传,那么他们得到两个不同的临时上传帐号,对应两个临时上传目录。 http://www.codeproject.com/aspnet/multiuploads.asp?forumid=13636&fr=51&select=1172683&df=100#xx1172683xx看看这篇文章,看有没有收获,其实像你这种直接上传那么大的东西,应该不是经常有的, 最好还是用FTP 一个很麻烦的sql查询问题! 怎么样做下载 能不让用户点击下载文件的时候用下载工具打开 年前棘手问题,求解决,求安心过年 sql锁表解表 有没有遇到过用户被莫名退出,跳转到登陆页的? 求助一段删除文件的代码 datagridview Jquery uploadify 获取的上传文件中文名为乱码 哪位有这样的菜单 求救,请各位大虾帮帮忙,急急急! 请问HyperLink中怎么带参数呢? 为什么这样JS使用<script language=javascript src="xx"></script>不顶用?
上传按钮事件:
{string fname,path;
fname=System.IO.Path.GetFileName(filMyFile.Value.ToString()); //获得要上传的文件的文件名(文件名带扩展名) filMyFile.Value 是上传文件的路径
path=DBCon.mp3UploadString()+ddlmPath.SelectedItem.Text; //上传路径
HttpPostedFile myFile = filMyFile.PostedFile; // 获得一个postedfile
int nFileLen = myFile.ContentLength; // 上传文件的长度
byte[] myData = new byte[nFileLen]; // 转换为字节流
myFile.InputStream.Read(myData,0,nFileLen);
string Mpath=Server.MapPath("//"); //服务器物理路径 路径要自己定义
string Mpath2=Mpath+fname;
WriteToFile(Mpath2,ref myData); //保存文件
}private void WriteToFile(string strPath, ref byte[] Buffer)
{
// 创建一个文件
FileStream newFile = new FileStream(strPath, FileMode.Create);
// 读文件
newFile.Write(Buffer,0,Buffer.Length);
// 关闭文件
newFile.Close();
}
<%@ Page language="c#" Codebehind="upMoreFile.aspx.cs" AutoEventWireup="false" Inherits="CommonFunction.upMoreFile" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>upMoreFile</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<script language="JavaScript">
function addFileControl()
{
var str = '<INPUT type="file" NAME="File">'
document.getElementById('FileCollection').insertAdjacentHTML("beforeEnd",str)
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="upMoreFile" method="post" encType="multipart/form-data" runat="server">
<asp:label id="Title" Runat="server"></asp:label>
<P id="FileCollection"><INPUT type="file" name="File">
</P>
<P><input onclick="addFileControl()" type="button" value="增加(File)">
<asp:button id="Upload" Runat="server" Text="上传" Width="56px"></asp:button><input style="WIDTH: 56px; HEIGHT: 24px" onclick="this.form.reset()" type="button" value="重置">
</P>
<P align="center"><asp:label id="strStatus" runat="server" BorderColor="White" BorderStyle="None" Width="500px"
Font-Size="9pt" Font-Bold="True" Font-Names="宋体"></asp:label></P>
</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;
namespace CommonFunction
{
/// <summary>
/// upMoreFile 的摘要说明。
/// </summary>
public class upMoreFile : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Upload;
protected System.Web.UI.WebControls.Label Title;
protected System.Web.UI.WebControls.Label strStatus;
private void Page_Load(object sender, System.EventArgs e)
{
Title.Text = "<h3>多文件上传</h3>";
Upload.Text = "开始上传";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Upload.Click += new System.EventHandler(this.Upload_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Upload_Click(object sender, System.EventArgs e)
{
upMorefile();
}
private bool upMorefile()
{
//遍历File表单元素
System.Web.HttpFileCollection files = System.Web.HttpContext.Current.Request.Files;
//状态信息
System.Text.StringBuilder strMsg = new System.Text.StringBuilder("上传的文件信息分别为:<hr color=red>");
int fileCount;
int filecount = files.Count;
try
{
for(fileCount = 0;fileCount<files.Count;fileCount++)
{
//定义访问客户端上传文件的对象
System.Web.HttpPostedFile postedFile = files[fileCount];
string fileName, fileExtension;
//取得上传得文件名
fileName = System.IO.Path.GetFileName(postedFile.FileName);
if(fileName != String.Empty)
{
//取得文件的扩展名
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 color=red>");
//保存到指定的文件夹
postedFile.SaveAs(Server.MapPath("upedFile/") + fileName);
}
}
strStatus.Text = strMsg.ToString();
return true;
}
catch(System.Exception error)
{
strStatus.Text = error.Message;
return false;
}
}
}
}转 csdn上的一位兄弟
我详细说一下 要实现的功能, 请各位高手指点,我要实现的是,从本地计算机的某个文件夹中取出 数据(数据量很大,文件个数很多。 文件个数*单个文件大小 >> 几十G ) 然后上传的服务器上的某个文件夹中,谢谢
2.管理员通过FTP上传文件。
3.管理员在Web管理界面选择“此次上传结束”,此时该临时FTP上传帐号被删除,那么该临时上传目录应该就没有人有写权限的了。接着,程序就可以递归遍历该临时上传目录,把音乐文件复制到真正的音乐存放目录,同时进行重命名和记录到数据库的操作。整个复制和记录工作完成后,删除该临时上传目录。这样的好处就是既实现了FTP,而且每个上传过程都是独立的不会相互干扰的,不会发生任何读写冲突。如果两个管理员同时要求上传,那么他们得到两个不同的临时上传帐号,对应两个临时上传目录。
看看这篇文章,看有没有收获,
其实像你这种直接上传那么大的东西,应该不是经常有的, 最好还是用FTP