如何引用C:\用户\ Public目录编程方式在C#方式、目录、用户、Public

由网友(是男人就像爷们一样)分享简介:它是安全的编程方式引用公用文件夹:Is it safe to programmatically reference the public folder through:Directory = System.Environment.GetEnvironmentVariable("public")+"MyCompany...

它是安全的编程方式引用公用文件夹:

Is it safe to programmatically reference the public folder through:

Directory = System.Environment.GetEnvironmentVariable("public")+"MyCompanyName" // etc.

或是否有更好的办法?

or is there a better way?

此外,如果有人删除了环境变量公开的,这是可以放心使用的不同语言的操作系统?

Again, what if someone deletes the environment variable for public, and is this safe to use for different language OSs?

本如下:How安装从VS 2010部署安装项目在Windows 7中的公共目录。

推荐答案

这取决于你想要达到什么目的。 有一个名为 SpecialFolder ENUM。你可以用它来获取路径一些目录。 例如:

It depends on what you want to achieve. There is a ENUM called SpecialFolder. You can use it to get the Path to some Directories. For Example:

System.Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory)

指向C:用户公用桌面

points to "C:UsersPublicDesktop".

恕我直言,你的方式是没有错的,但我会做一些异常处理的情况下,ENVVAR真的丢失。 你也可以使用ENUM以CommonDesktopDirectory,摆脱了桌面的部分。

IMHO, your way isn't wrong, though i would do some Exception Handling in case the EnvVar is really missing. Also you could use the ENUM with "CommonDesktopDirectory" and get rid of the "Desktop" part.

阅读全文

相关推荐

最新文章