【 解 説 】
相対パスを取得するにはUriクラスを使用します。.NET Framework 2.0からURIクラスの使用方法が変わりました。
【 例 文 】
[.NET Framework 2.0の場合]
1 2 3 4 5 6 7 8 9 |
//.NET Framework 2.0 Uri startupPath, targetPath; startupPath = new Uri(Application.StartupPath + "\"); targetPath = new Uri(value); //startupPathから見た、targetPathを相対パスで取得する Console.WriteLine(startupPath.MakeRelativeUri(targetPath).ToString()); |
[.NET Framework 1.1の場合]
1 2 3 4 5 6 7 |
Uri startupPath, targetPath; startupPath = new Uri(Application.StartupPath + "\", true); targetPath = new Uri(value, true); //startupPathから見た、targetPathを相対パスで取得する Console.WriteLine(startupPath.MakeRelative(targetPath)); |
■お薦め参考関連資料
Microsoft、Visual Studio、Visual Basic、Visual C#、Windows Vista、Windows Server、SQL Server、Visual C++、Visual Web Developerは、米国 Microsoft Corporationの米国及びその他の国における登録商標または商標です。