使应用程序能够在安装文件夹中写入文件 [英] Make app able to write files in the installation folder

查看:78
本文介绍了使应用程序能够在安装文件夹中写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要在运行时创建文件.我做了一个安装程序,但Windows不允许程序在安装文件夹中写入.如何解决此问题?一切都需要以编程方式进行,因为该程序将安装在任何PC上.我使用C#4.0

My app needs to create files at runtime. I made an installer but Windows don''t let the program write in the installation folder.How do I solve this problem? Everything needs to be programmatically ''cause the program will be installed in any pc. I use C# 4.0

推荐答案

如果您的应用程序需要在运行时创建文件,则需要根据文件的使用情况将它们放置在不同的位置.
如果该文件供应用程序使用,而不管用户是谁,请使用返回的路径;
If your application needs to create files at runtime you need to put them in different locations depending on the usage of the files.
If the file is for the application to use regardless of the user use the path returned by;
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)


在上述代码返回的路径中为您的应用程序添加一个文件夹,并将文件存储在其中.

如果文件是用户特定的,请使用以下方法返回的路径:


Add a folder for your application to the path returned by the above code and store the files in there.

If the file is user specific use the path returned by;

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)


再次在上述代码返回的路径中为您的应用程序添加一个文件夹,并将用户特定的文件存储在其中.

通常,仅使用上面的路径来存储用户特定的数据就可以逃脱,但是还有另一条可以使用的路径;


Again add a folder for your application to the path returned by the above code and store the user specific files in there.

Generally you can get away with only using the above path for user specific data but there is another path which can be used which is;

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)


两者之间的区别在于,第一个与域中的漫游用户一起使用,并被复制到用户登录到的其他计算机上,第二个是特定于一台计算机的用户数据.

为什么要这样做,因为Microsoft增强了Program Files目录的安全性,因此安装程序只将存储在该文件中的文件放在那里.


The difference between the two is that the first one is used with roaming users on a domain and is replicated onto other computers a user logs onto where the second one is user data that is specific to a single machine.

Why do you have to do it this way, because Microsoft increased security on the Program Files directory so that the only files that are stored there were put there by an installer.


也许只是盲目投掷,偶然发现了Folder类? :rolleyes:

Windows安装程序可以在安装过程中创建文件夹结构.
And have you perhaps just blindly cast about and stumbled on the Folder class? :rolleyes:

A Windows installer can create a folder structure during an installation.


这篇关于使应用程序能够在安装文件夹中写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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