AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别
2015-07-08 14:46
661 查看
事由:
开始用vs2008.在vs2005下复制相关代码
PicDir = Application.StartupPath & "\SmallPic"
2008中提示有误。 vs2008没法直接用Application.StartupPath
找了一下才明白,原来Application对象是来源于:System.Windows.Forms ,以前vs2005都直接调用的。
以后最好用:System.AppDomain.CurrentDomain.BaseDirectory 不过要注意路径最后多了一个“ \”
值得注意: PicDir = IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmallPic")
------
// 获取程序的基目录。
System.AppDomain.CurrentDomain.BaseDirectory
// 获取模块的完整路径。
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
// 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。
System.Environment.CurrentDirectory
// 获取应用程序的当前工作目录。
System.IO.Directory.GetCurrentDirectory()
// 获取和设置包括该应用程序的目录的名称。
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
// 获取启动了应用程序的可执行文件的路径。
System.Windows.Forms.Application.StartupPath
// 获取启动了应用程序的可执行文件的路径及文件名
System.Windows.Forms.Application.ExecutablePath
C# WinForm中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别示例如下:
private void Frm_Server_Load(object sender, EventArgs e)
{
MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory);
MessageBox.Show(Application.StartupPath );
}
说明:
1. AppDomain.CurrentDomain.BaseDirectory 返回结果为: D:\mycode\
Application.StartupPath 返回结果为: D:\mycode
2. Application.StartupPath 只能用于WinForm窗体中,
而AppDomain.CurrentDomain.BaseDirectory既可以用于WinForm窗体中,也可以用于类库DLL文件中.
开始用vs2008.在vs2005下复制相关代码
PicDir = Application.StartupPath & "\SmallPic"
2008中提示有误。 vs2008没法直接用Application.StartupPath
找了一下才明白,原来Application对象是来源于:System.Windows.Forms ,以前vs2005都直接调用的。
以后最好用:System.AppDomain.CurrentDomain.BaseDirectory 不过要注意路径最后多了一个“ \”
值得注意: PicDir = IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmallPic")
------
// 获取程序的基目录。
System.AppDomain.CurrentDomain.BaseDirectory
// 获取模块的完整路径。
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
// 获取和设置当前目录(该进程从中启动的目录)的完全限定目录。
System.Environment.CurrentDirectory
// 获取应用程序的当前工作目录。
System.IO.Directory.GetCurrentDirectory()
// 获取和设置包括该应用程序的目录的名称。
System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
// 获取启动了应用程序的可执行文件的路径。
System.Windows.Forms.Application.StartupPath
// 获取启动了应用程序的可执行文件的路径及文件名
System.Windows.Forms.Application.ExecutablePath
C# WinForm中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别示例如下:
private void Frm_Server_Load(object sender, EventArgs e)
{
MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory);
MessageBox.Show(Application.StartupPath );
}
说明:
1. AppDomain.CurrentDomain.BaseDirectory 返回结果为: D:\mycode\
Application.StartupPath 返回结果为: D:\mycode
2. Application.StartupPath 只能用于WinForm窗体中,
而AppDomain.CurrentDomain.BaseDirectory既可以用于WinForm窗体中,也可以用于类库DLL文件中.
相关文章推荐
- Android 出现的小问题 an internal error occurred during:”check Android SDk“
- 编译Android程序
- java中object常用方法
- Swift学习笔记系列——(4)控制流
- MyBatis源码分析之MappedStatemenet,SqlSource,DynamicContext
- 那些动画效果很炫的Android及iOS开源项目
- [Objective-C] 目标文件反编译得到Objecitve-C源文件
- Android万能播放器
- ActiveAndroid.initialize使用笔记
- 8 个最优秀的 Android Studio 插件
- iOS 8 AutoLayout与Size Class
- Android高手速成
- IOS开发之----常用函数和常数(转)
- Android中Java和JavaScript交互
- unity3d 渲染路径(延迟光照,正向渲染,顶点光照)
- Android Frame(逐帧动画)的使用
- Native App、Web App 还是Hybrid App?(转)
- unity Json
- webview中html页面点击文本框整个页面放大
- 聊聊Web App、Hybrid App与Native App的设计差异(转)