C# Windows アプリケーションから .xml ファイルを読み込もうとしている .net Windows アプリケーションが 1 つあります。
しかし、私はエラーが発生しています:
パス 'c:\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\~\Files\test.xml' の一部が見つかりませんでした。
しかし、私のファイルは、アプリケーションではなく アプリケーション内にFiles
あるフォルダにありますWindowsFormsApplication1
\bin\Debug
では、なぜそれが検索されているの\bin\Debug
ですか?
form.cs のコード
DataSet dsAuthors = new DataSet("authors");
string filePath = @"~/Files/test.xml";
dsAuthors.ReadXml(filePath);
また、Web アプリケーションで行うように Server.MapPath を使用する方法があることを教えてください。
私は次のような他の解決策を試しました:
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
System.IO.DirectoryInfo directoryInfo = System.IO.Directory.GetParent(appPath);
System.IO.DirectoryInfo directoryInfo2 = System.IO.Directory.GetParent(directoryInfo.FullName);
string path = directoryInfo2.FullName + @"\Files";
しかし、エラーが発生しています:
Access to the path is denied.