C#에서는 XML 파일이 만들어 졌는지 확인하고 파일을 만들지 않은 경우 XML 선언, 메모 및 부모 노드를 만들려고합니다.폼로드시 XML 파일을로드 할 때 오류 발생
:
내가 그것을로드하려고, 그것은 나에게이 오류 준다 "프로세스가 파일에 액세스 할 수 없습니다. 'C를 : \ FileMoveResults \ Applications.xml'다른 프로세스에서 사용하고 있기 때문에"
작업 관리자가 열려 있지 않은지 확인하고 열려있는 응용 프로그램이 없는지 확인했습니다. 무슨 일이 벌어지고 있는지에 대한 아이디어가 있습니까? 여기
//check for the xml file
if (!File.Exists(GlobalVars.strXMLPath))
{
//create the xml file
File.Create(GlobalVars.strXMLPath);
//create the structure
XmlDocument doc = new XmlDocument();
doc.Load(GlobalVars.strXMLPath);
//create the xml declaration
XmlDeclaration xdec = doc.CreateXmlDeclaration("1.0", null, null);
//create the comment
XmlComment xcom = doc.CreateComment("This file contains all the apps, versions, source and destination paths.");
//create the application parent node
XmlNode newApp = doc.CreateElement("applications");
//save
doc.Save(GlobalVars.strXMLPath);
내가이 문제를 해결하려면 사용하여 종료 코드입니다 : 여기
내가 사용하고있는 코드입니다 XML 파일 경우 (File.Exists (GlobalVars 확인 //!. strXMLPath)) {
사용 (XmlWriter를 xWriter = XmlWriter.Create (GlobalVars.strXMLPath)) { xWriter.WriteStartDocument(); xWriter.WriteComment ("이 파일에는 모든 응용 프로그램, 버전, 소스 및 대상 경로가 포함되어 있습니다."); xWriter.WriteStartElement ("application"); xWriter.WriteFullEndElement(); xWriter.WriteEndDocument(); }
빈 파일의'doc.Load()'는 예외를 throw합니다. – SLaks