System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

问题

在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) 在 System.IO.FileStream…ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) 在 System.IO.FileStream…ctor(String path, FileMode mode) 在
在这里插入图片描述

问题分析

一般先看是不是路径问题,我这里遇到的是路径问题

原先我的代码是:

  path = $"{dstFilePath}/{DateTime.Now.ToString("yyyyMMdd")}";
  if (!Directory.Exists(System.Web.HttpContext.Current.Server.MapPath(dstFilePath)))
  {
      Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(dstFilePath));
  }
  path = $"{path}/{dstFileName}";
  FileStream outfile = new FileStream(System.Web.HttpContext.Current.Server.MapPath(path), FileMode.Create);
  wk.Write(outfile);
  outfile.Close();

但是我得路径上是加了DateTime.Now.ToString("yyyyMMdd")文件夹,但是我判断创建的只有dstFilePath,因为找不到日期文件夹,所有造成报错

我把他改成创建path,就没问题了

 path = $"{dstFilePath}/{DateTime.Now.ToString("yyyyMMdd")}";
 if (!Directory.Exists(System.Web.HttpContext.Current.Server.MapPath(path)))
 {
     Directory.CreateDirectory(System.Web.HttpContext.Current.Server.MapPath(path));
 }
 path = $"{path}/{dstFileName}";
 FileStream outfile = new FileStream(System.Web.HttpContext.Current.Server.MapPath(path), FileMode.Create);
 wk.Write(outfile);
 outfile.Close();

总结:一般出现这种问题都是路径问题,看看文件路径是否存在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

润小仙女

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值