解決辦法:

使用以下兩個命名空間

using System.Reflection;
using System.IO;

string assemblyFilePath = Assembly.GetExecutingAssembly().Location;
string assemblyDirPath = Path.GetDirectoryName(assemblyFilePath);

//或是直接弄成一行
string assemblyDirPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

Console.WriteLine(assemblyFilePath); //這個是包含該檔案的完整路徑
Console.WriteLine(assemblyDirPath); //這個就是該檔案所在的目錄路徑


//另一種方法是使用 System.Environment.CurrentDirectory

所以 (assemblyDirPath + "\XXXX.xxx"); 這行就是相對路徑拉!!

arrow
arrow
    全站熱搜

    AwEi 發表在 痞客邦 留言(0) 人氣()