111,098
社区成员




private string WriteTempFile(HttpPostedFile uploadFile, int chunk)
{
string tempDir = FileHelper.GetTempPath();
if (!Directory.Exists(tempDir))
{
Directory.CreateDirectory(tempDir);
}
string fullName = string.Format("{0}\\{1}.part", tempDir, uploadFile.FileName);
if (chunk == 0)
{
//如果是第一个分块,则直接保存
uploadFile.SaveAs(fullName);
}
else
{
//如果是其他分块文件 ,则原来的分块文件,读取流,然后文件最后写入相应的字节
FileStream fs = new FileStream(fullName, FileMode.Append);
if (uploadFile.ContentLength > 0)
{
int FileLen = uploadFile.ContentLength;
byte[] input = new byte[FileLen];
// Initialize the stream.
System.IO.Stream MyStream = uploadFile.InputStream;
// Read the file into the byte array.
MyStream.Read(input, 0, FileLen);
fs.Write(input, 0, FileLen);
fs.Close();
}
}
return fullName;
}