问题解决,用MemoryStream代替Stream进行上传即可,没有想得那么麻烦。代码如下(项目中拷贝过来简化后的代码,不保证能直接执行):
MemoryStream ms = new MemoryStream();
gcSpreadSheet1.SaveExcel(ms, ExcelFileFormat.XLSX);
WebClient webClient = new WebClient();
webClient.OpenWriteCompleted += (r,args) =>{
try
{
Stream stream = args.Result;
byte[] buffer = new byte[4096];
int readcount = 0;
fileStream.Position = 0;
//将需要上传的流读取到指定的字节数组中
while ((readcount = fileStream.Read(buffer, 0, buffer.Length)) > 0)
{
//将指定的字节数组写入到目标地址的流
stream.Write(buffer, 0, readcount);
}
fileStream.Close();
stream.Close();
if (DoActionCompleted != null)
DoActionCompleted();
}
catch (Exception ee)
{
//throw new Exception(ee.Message.ToString());
}
}
谢谢版主。。 |