读书人

asp.net 资料上传

发布时间: 2013-10-12 11:54:02 作者: rapoo

asp.net 文件上传


DataTable dt2 = ViewState["dt2"] as DataTable;

for (int i = 0; i < dt2.Rows.Count; i++)
{
FileInfo file = new FileInfo(dt2.Rows[i]["photo_path"].ToString());
Stream stream = file.OpenRead();
//int index = SourceFilePath.LastIndexOf("\\", SourceFilePath.Length - 1);
string SourceFilePath = this.hidPath1.Value;

int index = SourceFilePath.LastIndexOf("\\", SourceFilePath.Length - 1);
string strFileName = SourceFilePath.Substring(index + 1);


if (stream.CanRead)
{
using (FileStream fs = new FileStream(newPath + strFileName, FileMode.Create))
{
byte[] buffer = new byte[stream.Length];
int totalLength = (int)stream.Length;
int readLength = 0;
stream.Position = 0;
while (totalLength > 0)
{
int readCount = stream.Read(buffer, readLength, Math.Min(totalLength, int.MaxValue));
if (readCount == 0)
{
break;
}
fs.Write(buffer, 0, totalLength);
readLength += readCount;
totalLength -= readCount;
}
fs.Close();
}
stream.Close();

return true;
}
else
{
return false;
}



}



这里for循环没有,只执行一遍,明明有2条数据
求解 asp.net string 数据 path buffer
[解决办法]
可能是你那return返回了吧
[解决办法]
dt2.Rows.Count你的这个是两条么? 我看你代码里也没怎么用到i 可以使用foreach(DataRow drr in dt2.Rows ){}
[解决办法]
break了吧
[解决办法]
应该是return返回了,循环就不走了。
[解决办法]
可能是return了 楼主打个断点 debug就知道了
[解决办法]
return会跳出循环

读书人网 >asp.net

热点推荐