c# - .NET Winforms c# 上传大文件

标签 c# .net winforms upload

当文件长度高于 18 mb 时,我收到此错误:

stream does not support concurrent IO read or write operations

错误已定位在本节中:

requestStream.Write(header, 0, header.Length);
if (fileData != null)
{
     // write the file data, if any
     byte[] buffer = new Byte[checked((uint)Math.Min(8192, (int)fileData.Length))];
     int bytesRead;

     try
     {
          while ((bytesRead = fileData.Read(buffer, 0, buffer.Length)) != 0)
          {
               //throws an exception after 3000 loops aprox
               requestStream.Write(buffer, 0, bytesRead);
          }
     }
     catch (Exception ex)
     {
          string aux = ex.Message;
     }
}

// write footer
requestStream.Write(footer, 0, footer.Length);
return webrequest.GetResponse();

我尝试使用lock语句,sendChunked = trueAllowWriteStreamBuffering = false但我无法正确上传文件。

提前致谢

最佳答案

也许当循环尝试将数据上传(写入)到流时,Web 服务器会发送一条错误消息(读取),指出已超出大小限制。您可以尝试使用 Wireshark 或其他网络嗅探器检查服务器和程序之间发送的内容。

关于c# - .NET Winforms c# 上传大文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21879742/

相关文章:

.net - 获取当前登录的远程机器的交互式用户?

.net - 带反向引用的重复析取如何工作?

c# - 附加命令

c# - 作业不存在 (Quartz .NET)

c# - NuGet 包将非托管 dll 复制到根目录而不是 bin

c# - 如何将 'end of text' (ETX, ASCII 3) 放入字符串中?

c# - 使用 Entity Framework ,返回 DateTime 列的日期端口等于今天的所有行

c# - 在 form1.cs 和 program.cs 之间传递数据

c# - .Net 中的同步 ListView

C# 为什么不能设置动态创建的组合框的 selectedValue?