So far in development, my application has been storing its databases in the app base directory. When it is deployed this will be in program files so I cant keep them there!
到目前为止,我的应用程序一直在将其数据库存储在app基本目录中。部署时,这将是程序文件,所以我不能保持它们!
The obvoius places are:
obvoius的地方是:
Environment.SpecialFolder.LocalApplicationData
Environment.SpecialFolder.ApplicationData
One problem is that data downloads can be run from sceduled tasks so I would have to ensure tasks were run under the same user.
一个问题是数据下载可以从已调度的任务运行,因此我必须确保任务在同一用户下运行。
The major issue is that after a couple of years, these database files could total 5 to 10GB, so I feel like I should give the user an option after install to choose the database location. I'd have to ensure that it was writable and not a network location.
主要问题是,几年后,这些数据库文件总共可以达到5到10GB,所以我觉得我应该在安装后给用户一个选项以选择数据库位置。我必须确保它是可写的而不是网络位置。
What solutions have others come up with?
其他人提出了哪些解决方案?
1 个解决方案
#1
About checking the write access to a directory: So far I have found no better way than to create a file in the directory and immediately delete it. If you encounter an error during these steps, you have insufficient privilegs. (Just remember to first check if there is enough free space on the drive).
关于检查对目录的写访问权限:到目前为止,我发现没有比在目录中创建文件更好的方法并立即删除它。如果在这些步骤中遇到错误,则您的权限不足。 (请记住首先检查驱动器上是否有足够的可用空间)。
I once tried to solve this programmatically by going through the access control lists, but then i encountered a dir where I had write priviliges, but not the right to list the ACLs...
我曾尝试通过访问控制列表以编程方式解决此问题,但后来我遇到了一个我写了特权的目录,但没有列出ACL的权利......
You can check if a given drive is a network share by using the DriveType
property of the System.IO.DriveInfo
object. As for handling UNC pathes, I have yet to find a better way than (myPath.Substring(0,2) == @"\\")
您可以使用System.IO.DriveInfo对象的DriveType属性检查给定驱动器是否为网络共享。至于处理UNC pathes,我还没有找到比(myPath.Substring(0,2)== @“\\”更好的方法)
#1
About checking the write access to a directory: So far I have found no better way than to create a file in the directory and immediately delete it. If you encounter an error during these steps, you have insufficient privilegs. (Just remember to first check if there is enough free space on the drive).
关于检查对目录的写访问权限:到目前为止,我发现没有比在目录中创建文件更好的方法并立即删除它。如果在这些步骤中遇到错误,则您的权限不足。 (请记住首先检查驱动器上是否有足够的可用空间)。
I once tried to solve this programmatically by going through the access control lists, but then i encountered a dir where I had write priviliges, but not the right to list the ACLs...
我曾尝试通过访问控制列表以编程方式解决此问题,但后来我遇到了一个我写了特权的目录,但没有列出ACL的权利......
You can check if a given drive is a network share by using the DriveType
property of the System.IO.DriveInfo
object. As for handling UNC pathes, I have yet to find a better way than (myPath.Substring(0,2) == @"\\")
您可以使用System.IO.DriveInfo对象的DriveType属性检查给定驱动器是否为网络共享。至于处理UNC pathes,我还没有找到比(myPath.Substring(0,2)== @“\\”更好的方法)