使用C#访问系统目录 [英] Access to system directories using C#

查看:97
本文介绍了使用C#访问系统目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含本地数据库
的程序,当我从非系统目录运行该程序时,它运行良好,但是当我从一个程序目录(如程序文件目录)运行时,我无法访问我的数据库
Im使用c#wpf。不知道如何访问我的数据库:/

I have a program which contains a local database It works fine when im running it from a non-system Directory , but when im running it from a system directory like program files directory i cant access to my database Im using c# wpf . Have no idea how to access my database :/

通过使用实体数据模型访问该数据库,该模型与应用程序目录中的该数据库一起使用(该目录将位于程序文件中)像我安装的所有其他应用程序一样,例如Adobe应用程序MS Office等。)如何在未经用户许可的情况下访问程序文件目录中的数据? :((

tho im using an Entity Data Model which works with that database in application directory (which is going to be in program files Directory Like Every other application i install e.g Adobe applications MS Office etc .. ) how do they have access to their datas in program files directory without getting any permission from user ?!!! :((

推荐答案

您不应该将程序数据保存在程序应用程序文件夹中,因为如果不更改它就无法访问它。用户权限或使用管理权限。您应该使用环境.SpecialFolder

You should not save program data in your programs application folder as you do not have access to it without changing the users permissions or using administrative permissions. You should use an Environment.SpecialFolder for it.

例如

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\YourApplication"

例如,正在使用Adobe Flash或MS Office。

This is also what e.g. Adobe Flash or MS Office are using.

这篇关于使用C#访问系统目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆