当前位置:  开发笔记 > 编程语言 > 正文

无法上传超过5000 k大小的zip文件

如何解决《无法上传超过5000k大小的zip文件》经验,为你挑选了1个好方法。

我对C#更新鲜,我可以将文件上传到服务器,但是当我尝试上传超过5000k的大小时,它会给出异常.

这是我的C#代码

private void UploadFile(string filename)
{
  try
  {
    PeopleMatrixService peopleMetrixService = new PeopleMatrixService();

    String strFile = System.IO.Path.GetFileName(filename);
    // TestUploader.Uploader.FileUploader srv = new TestUploader.Uploader.FileUploader();
    FileInfo fInfo = new FileInfo(filename);
    long numBytes = fInfo.Length;
    double dLen = Convert.ToDouble(fInfo.Length / 10000000);
    if (dLen < 8)
    {
      FileStream fStream = new FileStream(filename, FileMode.Open, FileAccess.Read);
      BinaryReader br = new BinaryReader(fStream);
      byte[] data = br.ReadBytes((int)numBytes);
      br.Close();
      string sTmp = peopleMetrixService.UploadFile(data, strFile);
      fStream.Close();
      fStream.Dispose();
      MessageBox.Show("File Upload Status: " + sTmp, "File Upload");
    }
    else
    {
      MessageBox.Show("The file selected exceeds the size limit for uploads.", "File Size");
    }
  }
  catch (Exception ex)
  {
    MessageBox.Show(ex.Message.ToString(), "Upload Error");
  }
}

和我在webservice中的代码

[WebMethod]
public string UploadFile(byte[] f, string fileName)
{
  try
  {
    MemoryStream ms = new MemoryStream(f);
    FileStream fs = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath("~/Response Attachments/") + fileName, FileMode.Create);
              //FileStream fs = new FileStream(Server.MapPath("~/Response Attachments/") + fileName, FileMode.Create);
    ms.WriteTo(fs);
    ms.Close();
    fs.Close();
    fs.Dispose();
    return "OK";
  }
  catch (Exception ex)
  {
    return ex.Message.ToString();
  }
}

Element.. 6

默认情况下,maxRequestLength设置为4096(4mb),您需要在web.config文件中将其更改为更大的大小.

请参阅:http://msdn.microsoft.com/en-us/library/e1f13641(VS.80).aspx



1> Element..:

默认情况下,maxRequestLength设置为4096(4mb),您需要在web.config文件中将其更改为更大的大小.

请参阅:http://msdn.microsoft.com/en-us/library/e1f13641(VS.80).aspx

推荐阅读
家具销售_903
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有