如何解决“访问路径被拒绝”的问题C# Winform 的问题?

发布于 2025-01-16 22:49:31 字数 626 浏览 4 评论 0原文

我编写了一个程序来修改文件,当我定期运行它时它运行良好:

string modifiedFile = tmpPath + "\\Ext\\out.dat";
    FileStream writeStream = File.OpenWrite(modifiedFile);
    byte[] newData = new byte[2];
    newData[0] = 0x4B;
    newData[1] = 0x4B;
    writeStream.Seek(0, SeekOrigin.Begin);
    writeStream.Write(newData, 0, newData.Length);
    writeStream.Close();

但是如果我从电子邮件客户端运行它,该客户端有一封带有附加文件的电子邮件,当我单击附加文件时(格式已关联)到程序),程序运行但抛出错误:

访问路径 'C:\Users\admin\AppData\Local\Temp\Ext\out.dat' 被拒绝

我检查了文件夹“C:\Users\admin\AppData\Local\Temp\Ext”和 out.dat 文件就在那里。我应该怎么做才能解决这个问题?好像系统不允许我修改这个文件?

I have made a program to modify a file, it works well when I run it regularly:

string modifiedFile = tmpPath + "\\Ext\\out.dat";
    FileStream writeStream = File.OpenWrite(modifiedFile);
    byte[] newData = new byte[2];
    newData[0] = 0x4B;
    newData[1] = 0x4B;
    writeStream.Seek(0, SeekOrigin.Begin);
    writeStream.Write(newData, 0, newData.Length);
    writeStream.Close();

But if I run it from the Email client, which has an email with the attached file, when I click on the attached file (the format has associated to the program), the program runs but throws an error:

Access to the path 'C:\Users\admin\AppData\Local\Temp\Ext\out.dat' is denied

I checked the folder "C:\Users\admin\AppData\Local\Temp\Ext" and the out.dat file is there. What should I do to resolve this? It seems the system doesn't allow me to modify the file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文