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();

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

Installing the following packages: git By installing, you accept licenses for the packages. Progress: Downloading chocolatey-compatibility.extension 1.0.0... 100% chocolatey-compatibility.extension not installed. An error occurred during installation: 对路径“C:\ProgramData\chocolatey\lib\chocolatey-compatibility.extension”的访问被拒绝。 chocolatey-compatibility.extension package files install failed with exit code 1. Performing other installation steps. This is try 1/3. Retrying after 300 milliseconds. Error converted to warning: 对路径“C:\ProgramData\chocolatey\.chocolatey”的访问被拒绝。 This is try 2/3. Retrying after 400 milliseconds. Error converted to warning: 对路径“C:\ProgramData\chocolatey\.chocolatey”的访问被拒绝。 Maximum tries of 3 reached. Throwing error. Cannot create directory "C:\ProgramData\chocolatey\.chocolatey". Error was: System.UnauthorizedAccessException: 对路径“C:\ProgramData\chocolatey\.chocolatey”的访问被拒绝。 在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost) 在 chocolatey.infrastructure.filesystem.DotNetFileSystem.<>c__DisplayClass54_0.<CreateDirectory>b__1() 在 chocolatey.infrastructure.tolerance.FaultTolerance.<>c__DisplayClass1_0.<Retry>b__0() 在 chocolatey.infrastructure.tolerance.FaultTolerance.Retry[T](Int32 numberOfTries, Func`1 function, Int32 waitDurationMilliseconds, Int32 increaseRetryByMilliseconds, Boolean isSilent) 在 chocolatey.infrastructure.tolerance.FaultTolerance.Retry(Int32 numberOfTries, Action action, Int32 waitDurationMilliseconds, Int32 increaseRetryByMilliseconds, Boolean isSilent) 在 chocolatey.infrastructure.filesystem.DotNetFileSystem.CreateDirectory(String directoryPath) 在 chocolatey.infrastructure.filesystem.DotNetFileSystem.EnsureDirectoryExists(String directoryPath, Boolean ignoreError) Chocolatey installed 0/0 packages. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log). 对路径“C:\ProgramData\chocolatey\.chocolatey”的访问被拒绝。 是什么意义?如何解决?
最新发布
06-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

润小仙女

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

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

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

打赏作者

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

抵扣说明:

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

余额充值