小菜来袭 2017-03-31 12:08 采纳率: 40%
浏览 1651
已采纳

c# webserver上传文件到服务器的问题

c# webserver上传文件到服务器的问题 遇到100多M的文件直接报 操作超时
我在web.config文件里面也已经配置了

<system.web>
     <httpRuntime maxRequestLength="5120000" executionTimeout ="360000"/>

但是没有用 下面是代码

webserver

        //上传文件至服务器
        [WebMethod]
        public bool UploadFile(byte[] fs, string path, string fileName)
        {
            bool flag = false;
            try
            {
                //获取上传案例图片路径  
                path = Server.MapPath(path);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                //定义并实例化一个内存流,以存放提交上来的字节数组。  
                MemoryStream m = new MemoryStream(fs);
                //定义实际文件对象,保存上载的文件。  
                FileStream f = new FileStream(path + "\\" + fileName, FileMode.Create);
                //把内内存里的数据写入物理文件  
                m.WriteTo(f);
                m.Close();
                f.Close();
                f = null;
                m = null;
                flag = true;
            }
            catch (Exception ex)
            {
                flag = false;
            }
            return flag;
        }

c/s界面代码

    string path = txtUrl.Text.Trim(); ;//本地路径  
    byte[] bytes = GetBytesByPath(path);//获取文件byte[]  
              public static byte[] GetBytesByPath(string path)
        {
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
            BinaryReader br = new BinaryReader(fs);
            byte[] bytes = br.ReadBytes((int)fs.Length);
            fs.Flush();
            fs.Close();
            return bytes;
        }           
                    webdate.UploadFile(bytes, uploadPath, FileName)

webdate 是我实例化webserver的

有没有本地直接复制文件 然后通过webserver粘贴张服务器上的?

  • 写回答

1条回答 默认 最新

报告相同问题?