private static void saveDirAndFiles(TreeNode currNode)
{
using (StreamWriter file = new StreamWriter("test.html"))
{
if(currNode.ValueType=="DIR") //Are you a File or Directory
{
file.WriteLine(currNode.Value);//relative Name of Directory
}
else
{
string[] file1 = File.ReadAllLines(Path.GetFullPath(currNode.Value)); //EXEPTION
string prgcode = "";
foreach (string line in file1)
{
prgcode += line;
}
file.WriteLine(currNode.Value);//relative Name of File +...
file.WriteLine(String.Format("<code><pre>{0}</pre></code>", prgcode)); //... The Content of the File
}
}
foreach (TreeNode item in currNode.ChildNodes)
{
saveDirAndFiles(item);
}
}
この関数は、現在作業中のプロジェクトでのみ絶対パスを検索します。私のプロジェクトはデスクトップ上にあり、ファイル名はCディレクトリにあります。例外には、Project \ bin \ debug \ Filenameが見つかりません。Path.GetFullPath関数は現在のプロジェクトのみを検索します
'Path.GetFullPath'はドライブを検索しません。 [ドキュメントを読む](https://msdn.microsoft.com/en-us/library/system.io.path.getfullpath(v = vs.110).aspx)検索したとしても、 2つの異なるディレクトリに "Filename"という名前のファイルが2つある場合の問題は何ですか?ユーザーまたは設定ファイルからディレクトリの名前を取得する必要があります。 –