简体   繁体   English

尝试查看xml文件的路径时访问被拒绝

[英]Access denied when trying to view path of xml file

I am trying to get the path for an xml file i created in my lightswitch application. 我正在尝试获取在lightswitch应用程序中创建的xml文件的路径。 however i am getting System.Security.SecurityException error saying access is denied. 但是我收到System.Security.SecurityException错误,提示访问被拒绝。

var fileNme = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
    "Sample.xml");
Debug.WriteLine("app data path " + fileNme.ToString());

I am running the application locally on my computer and the eventually deploy to iis. 我正在计算机上本地运行该应用程序,并最终部署到iis。 Hopefully someone solution can help me out here. 希望有人解决方案可以在这里帮助我。
Thank you. 谢谢。

I am not an expert in LightSwitch, but you can try this: 我不是LightSwitch的专家,但是您可以尝试以下方法:

Assembly asm = Assembly.GetAssembly(typeof(<<assemblyNamespace>>.<<name_of_page_class>>));
string asmPath = asm.CodeBase;

string app_DataFolder = Path.GetFullPath(Path.GetDirectoryName(asmPath.Remove(0, "file:\\\\\\".Length)) + "\\..\\App_Data");

string filePath = Path.Combine(app_DataFolder, "Sample.xml");

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM