文件路径读取问题

greyrainbow2010 2012-04-21 03:47:34
Application.StartupPath调试发现是app.exe文件所在的路径

文件目录等级
app--bin--debug--app.exe
app--皮肤--1--1.doc

bin文件夹和皮肤文件夹同在app目录下
这时候我怎么才能取到 “1.doc”的路径呢??

就是相对路径和绝对路径的获取问题

...全文
135 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hoken2020856 2012-04-23
  • 打赏
  • 举报
回复
string path= Application.StartupPath.SubString(0,Application.StartupPath.Length-9);
string docpath=Path.Combin(path,"1\\1.doc");

文件是死的人是活的,你把它挪个方便读取的地方不就得了
liushideyizhenfeng 2012-04-23
  • 打赏
  • 举报
回复
可以看看这个网页
http://www.cnblogs.com/qianqianfy/archive/2009/07/08/1518974.html
小志 2012-04-23
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace DLAFMS.SysCommon {
/// <summary>
/// 公共类
/// </summary>
public class Global {
/// <summary>
/// 应用程序执行路径
/// </summary>
public static readonly string appDir = GetAppDir();

/// <summary>
/// 获取应用程序执行路径
/// </summary>
/// <returns>应用程序执行路径</returns>
private static string GetAppDir() {
string appName = Application.ExecutablePath;
string[] dirNames = appName.Split(new char[] { '\\' });

return appName.Replace(dirNames[dirNames.Length - 1], @"");
}
}
}

把皮肤放到debug目录下面,访问如下:
Global.appDir + @"皮肤\1.doc";
greyrainbow2010 2012-04-23
  • 打赏
  • 举报
回复
都不对啊,哎。
rayyu1989 2012-04-21
  • 打赏
  • 举报
回复
../../../皮肤/1/1.doc
greyrainbow2010 2012-04-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
单步调试 string 路径 =Application.StartupPath;
看看变量得到的知道 再根据实际情况进行追加字符串
[/Quote]
汗,我会追加字符串,但是我上面的需求是先要减几个字符串
不会减啊。
greyrainbow2010 2012-04-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
把皮肤放到debug目录下面

Application.StartupPath+"\\"+"皮肤"+"1.doc"
[/Quote]

这个我知道,但是不是我想要的
greyrainbow2010 2012-04-21
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
把皮肤放到debug目录下面

Application.StartupPath+"\\"+"皮肤"+"1.doc"
[/Quote]

这个我知道,但是不是我想要的
orochiheart 2012-04-21
  • 打赏
  • 举报
回复
单步调试 string 路径 =Application.StartupPath;
看看变量得到的知道 再根据实际情况进行追加字符串
事理 2012-04-21
  • 打赏
  • 举报
回复
把皮肤放到debug目录下面

Application.StartupPath+"\\"+"皮肤"+"1.doc"

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧