本文介绍了我怎样才能类库(没有应用程序对象)的内部构建Application.UserAppDataPath?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WinForms和控制台应用程序可以使用 Application.UserAppDataPath 。如果我想建立一个DLL相同的路径?我该怎么办呢?我知道, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)将开始...

Winforms and Console Applications can use Application.UserAppDataPath.What if I want to build the same path from a dll? How can I do that?I know that Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) would be the start...

推荐答案

您可以使用Application.UserAppDataPath从DLL - 只需从DLL项目中添加引用到System.Windows.Forms组装

You can use Application.UserAppDataPath from a DLL - simply add a reference to the System.Windows.Forms assembly from your DLL project.

但要注意,如果您的DLL用于Windows服务或服务器应用程序,如ASP.NET,它可能会在不具有配置文件的服务帐户运行 - 在这种情况下UserAppDataPath将不存在。这可能是主要的原因,应用类System.Windows.Forms命名空间。

However be aware that if your DLL is used in a Windows Service or Server application such as ASP.NET, it may run under an service account that does not have a profile - in this case UserAppDataPath won't exist. This is probably the main reason the Application class is in the System.Windows.Forms namespace.

这篇关于我怎样才能类库(没有应用程序对象)的内部构建Application.UserAppDataPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 05:24