C# 如何实现不用openFileDialog而指到当前程序所在跟目录bin文件下的文件

[复制链接]
查看11 | 回复2 | 2009-7-24 09:37:51 | 显示全部楼层 |阅读模式
String path = "我是绝对路径下面的txt:" + Application.StartupPath.ToString() + "\\我是文本.textApplication.StartupPath 指的是:你程序下面的\bin\Debug 同一级的目下的内容!注意:using System.Windows.Forms; 不引入不Application 就用不了!希望对LZ有帮助!
回复

使用道具 举报

千问 | 2009-7-24 09:37:51 | 显示全部楼层
/// ///获取当然exe文件所在的路径/// /// 路径public static string GetAbsolutePath(){
string FolderPath = string.Empty;
try
{
string strCodeBase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
int n = strCodeBase.LastIndexOf('/');
if (n > 8)
{
FolderPath = strCodeBase.Substring(8, n - 8);
// 8是 file:/// 的长度
}
else
{
FolderPath = ".";
}
}
catch
{
FolderPath = ".";
}
return FolderPath;}
回复

使用道具 举报

千问 | 2009-7-24 09:37:51 | 显示全部楼层
用相对路径吧string Path="bin\a.txt";
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行