【发布时间】:2015-07-11 00:53:45
【问题描述】:
安装后应用报错
拒绝访问文件
PathName\\BLsms.ocx
这里 PathName 是完整的路径。
高级安装程序用于创建安装程序。
然后应用程序安装在C Drive。
如何使这些文件可读写?
我正在使用此代码。
try
{
this.brlmfc = new BinaryReader(new FileStream("BLsms.ocx", FileMode.Open, FileAccess.ReadWrite,FileShare.Read));
this.brocx = new BinaryReader(new FileStream("BLrpi.lfc", FileMode.Open,FileAccess.ReadWrite));
this.brlmc = new BinaryReader(new FileStream("rpcgh.lfc", FileMode.Open,FileAccess.ReadWrite));
this.passkey1 = this.brlmfc.ReadString();
this.passkey2 = this.brocx.ReadString();
this.passkey3 = this.brlmc.ReadString();
}
catch (Exception e13)
{
MessageBox.Show(e13.Message);
i = 0;
}
我也在表单加载方法中尝试了以下代码。
FileIOPermission f2 = new FileIOPermission(FileIOPermissionAccess.AllAccess, Application.StartupPath+"\\BLsms.ocx");
f2.AddPathList( FileIOPermissionAccess.Read, Application.StartupPath+"\\BLrpi.lfc");
f2.AddPathList( FileIOPermissionAccess.Read, Application.StartupPath+"\\Brpcgh.lfc");
f2.Demand();
【问题讨论】:
-
您是使用
Application.StartupPath+"BLsms.ocx"获取正确路径还是必须使用Application.StartupPath+"\BLsms.ocx" -
是的,我在安装文件后。路径是 C:\Program Files (x86)\MyFolder\Myapp\BLsms.ocx
-
请尝试
FileIOPermission f2 = new FileIOPermission(FileIOPermissionAccess.AllAccess, Application.StartupPath+@"\BLsms.ocx");也用于其他两个文件 -
@PrettyDoll Check this link。它可能会对你有所帮助。
-
@PrettyDoll Check this link。它提供了有用的信息。
标签: c# .net visual-studio-2012 .net-4.0