我需要寫一個批量上傳的功能。我現在的做法是得到一個需要上傳文件的List...然后在用戶點擊上傳的時候,把List里面的文件遍歷的傳到服務器中去,我寫了如下的代碼,但我總認為會有些問題。因為剛用asp.net,沒什么經驗,請大家幫我看看。 protected void Button3_Click(object sender, EventArgs e)
{
maxno = 0;
UpLoadInfo tmpInfo = (UpLoadInfo)Session["loadInfo"]; //這里面存的文件列表是客戶端的本地文件路徑
//例如c:\\1.txt之類的 string dd = Server.MapPath("~/UploadFile/"); foreach (infoEntry tmpEntry in tmpInfo.theList)
{
File.Copy(tmpEntry.m_fullfileName, dd + tmpEntry.m_fileName, true); //我認為這一步執行會出問題,服務器看到客戶端的文件是c:\\1.txt,但卻不知道他的具體地址。雖然在本機上運行沒錯誤,但我覺得寫錯了,請大家指正
} tmpInfo.theList.Clear();
Response.Redirect("UpLoad.aspx"); }
{
maxno = 0;
UpLoadInfo tmpInfo = (UpLoadInfo)Session["loadInfo"]; //這里面存的文件列表是客戶端的本地文件路徑
//例如c:\\1.txt之類的 string dd = Server.MapPath("~/UploadFile/"); foreach (infoEntry tmpEntry in tmpInfo.theList)
{
File.Copy(tmpEntry.m_fullfileName, dd + tmpEntry.m_fileName, true); //我認為這一步執行會出問題,服務器看到客戶端的文件是c:\\1.txt,但卻不知道他的具體地址。雖然在本機上運行沒錯誤,但我覺得寫錯了,請大家指正
} tmpInfo.theList.Clear();
Response.Redirect("UpLoad.aspx"); }
解决方案 »
- dotnetnuke 6在VS2008下编译出错
- 高分求教 如何让asp.net自定义控件的内容写在body之内
- 用户登陆
- 终于解决!fckeditor的error loading fckstyles.xml问题!写出来与大家分享!
- 关于asp.net指定页面刷新的问题,请高手进来看看
- c:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll 引用的类“System.Data.DataSet”具有在未被引用的程序集中定义的基类或接
- 用什么函数检测 用户输入的生日日期,是否合法???
- IIS7.0怎么启用集成windows身份验证啊?
- 在dataGrid如何增加新行?
- Asp.net中操作Excel问题
- 用户上传了过大文件如何处理?
- 怪事
i=2;
function addFile()
{
// debugger; tb = document.getElementById( 'attAchments ');
newRow = tb.insertRow();
newRow.insertCell().innerHTML = ' <input type="file" name="FileUpload1" runat="server" onchange="CheckImgCss(this);" style="width: 260px"/> <input type=button value= "×" style=" height:18px; width:18px" onclick= "delFile(this.parentElement.parentElement.rowIndex) "> '; i++;
}
function delFile(index)
{
if(tb.rows.length >0 )
{
document.getElementById( 'attAchments ').deleteRow(index);
}
}
HttpFileCollection HFC = HttpContext.Current.Request.Files;