xxm0720
xxm0720
2018-01-09 07:55

C# 用UploadFile上传文件,保存到服务器中,但是在测试区正常,在正式去报错

10
  • c#
  • uploadfile
  • 服务器
    测试区的web.config没有配置requestLengthDiskThreshold,正式区好像也没有,但是在
    正式区上传附件报“Cannot access a closed file”,请问怎么解决?





    if (fupFile.PostedFile != null && fupFile.PostedFile.ContentLength > 0)
    {
        if (fupFile.HasFile)
        {

            ListItem item = new ListItem();
            item.Value = item.Text = fupFile.PostedFile.FileName;
            if (!lbxFile.Items.Contains(item))
            {
                lbxFile.Items.Add(item);
                files.Add(fupFile);
            }

        }
        if (files.Count > 0)
        {
            string WF_NO;
            string WF_Sale;
            string filename = "";
            string path = "d:\\Lorom\\ProductCenter\\WorkFlow\\FTPFile\\" + Session["wf_sale"].ToString() + "\\" + Session["WF_NO"].ToString() + "\\";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            lblShow.Text = fupFile.PostedFile.FileName;

            WF_Sale = Session["UserNO"].ToString();
            WF_NO = Session["WF_NO"].ToString();


            WCFHelperBase wcfBase = new WCFHelperBase();
            foreach (FileUpload fup in files)
            {
                if (fup.HasFile)

                    filename = fup.FileName;
                //string extend = Path.GetExtension(filename);

                // fupFile.PostedFile.SaveAs(Server.MapPath(path)+"\\"+filename);
                // Directory.CreateDirectory(path);
                //myFile.SaveAs(path + fupFile);
                wcfBase.csHelper.GetUnsignFile(WF_NO, filename, WF_Sale);
                fup.SaveAs(path + "/" + fup.FileName);//无法访问已关闭的文件

            }
            //Page.ClientScript.RegisterClientScriptBlock(typeof(string), "", @"<script>alert('上传成功!')</script>");
            wcfBase.CloseWCF();
            Response.AddHeader("Refresh", "0");
        }
    }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答