日期:2014-05-18  浏览次数:20978 次

文件路径读取问题
Application.StartupPath调试发现是app.exe文件所在的路径

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

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

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



------解决方案--------------------
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";