如何解决“访问路径被拒绝”的问题C# Winform 的问题?
我编写了一个程序来修改文件,当我定期运行它时它运行良好:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论