私は次のコードを持っています:
fileinfo = new FileInfo(filePathAndName);
if (!fileinfo.Exists)
{
using (xmlWriter = new XmlTextWriter(filePathAndName, System.Text.Encoding.UTF8))
{
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("root");
xmlWriter.WriteStartElement("objects");
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Close();
}
}
filePathAndNameは次のようになりますC:/MyApp%205/Produkter/MyApp%20Utveckling/Host/Orbit.Host.Dev/bin/ExceptionLog.xml.
フォルダは存在しますが、ファイルは存在しません。この場合、XmlTextWriterはファイルを作成する必要がありますが、代わりに。をスローしCould not find part of the path
ます。
それはおそらく私がここで忘れている非常に明白なことです、助けてください。
編集:これはパスが実際にどのように見えるかです:
C:\MyApp 5\Produkter\MyApp Utveckling\Host\Orbit.Host.Dev\Bin
そして、これはコードで使用されるURLが生成される方法です:
(new System.Uri(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase) + "\\ExceptionLog.xml")).AbsolutePath