나는 이것을 위해 모든 것을 조사했다. 검색에서 잘못 입력 한 것일 수도 있습니다. 확실하지 않습니다. 그래서 좋은 튜토리얼이나 예제를 알고 있다면 공유하십시오. 나는 배우려고 노력하고있어.디렉토리 목록을 xml 파일에 저장하는 방법 C#
저는 C# Windows Form app를 사용하고 있습니다. 정보 (이 경우 영화)가 XML 파일에 저장되어 있습니다. 이렇게 XML 파일을 저장했습니다.
//Now we add new movie.
XmlElement nodRoot = doc.DocumentElement;
string allMyChildren = nodRoot.InnerText;
string capitalized = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(movieEditNameTextbox.Text);
int indexLookForNewMake = allMyChildren.IndexOf(capitalized);
if (indexLookForNewMake >= 0)
{
MessageBox.Show("Movie is already saved.", "Error");
}
else
{
XmlElement el = doc.CreateElement("Name");
el.InnerText = capitalized;
doc.DocumentElement.AppendChild(el);
//Check if Year is really a Number.
if (movieEditYearTextbox.Text.All(Char.IsDigit))
{
//Remove ' cause it gives errors.
string capitalizedFixed = capitalized.Replace("'", "");
string capitalizedFinalFixed = capitalizedFixed.Replace("\"", "");
//Assign Attribute to each New one.
el.SetAttribute("Name", capitalizedFinalFixed);
el.SetAttribute("Type", movieEditTypeDropdown.Text);
el.SetAttribute("Year", movieEditYearTextbox.Text);
//Reset all fields, they don't need data now.
movieEditNameTextbox.Text = "";
movieEditYearTextbox.Text = "";
movieEditTypeDropdown.SelectedIndex = -1;
removeMovieTextbox.Text = "";
doc.Save("movie.xml");
label4.Text = "Movie Has been Edited";
loadXml();
}
else
{
//Error out. Year not a Number
MessageBox.Show("Check movie year. Seems it isn't a number.", "Error");
}
}
모두 정상적으로 작동합니다. 이제 내가하려는 것은 디렉터리를 선택할 수있는 곳으로 만들고, 디렉터리와 하위 디렉터리를 검색하고 파일 이름을 가져 와서 XML 파일에 저장합니다.
나는 이것을 달성하기 위해 이것을 사용했다. 그것은 목록을 가져옵니다. 그러나 그것을 구하지는 못합니다. 새로운 정보는 저장하지 않습니다.
LINQ는 다른 이유로 인해 충돌을 일으킬 수 있으므로 사용할 수 없습니다.
DirectoryInfo dirCustom = new DirectoryInfo(@"D:\Video");
FileInfo[] filCustom;
filCustom = dirCustom.GetFiles("*",SearchOption.AllDirectories);
//Open XML File.
XmlDocument doc = new XmlDocument();
doc.Load("movie.xml");
XmlElement el = doc.CreateElement("Name");
string fulCustoms = filCustom.ToString();
foreach (FileInfo filFile in filCustom)
{
string capitalized = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(filFile.Name);
string capitalizedFixed = capitalized.Replace("\"", "");
el.SetAttribute("Name", capitalizedFixed);
el.SetAttribute("Type", "EDIT TYPE");
el.SetAttribute("Year", "EDIT YEAR");
richTextBox1.AppendText(capitalizedFixed + "\r\n");
}
doc.Save("movie.xml");
label4.Text = "Movie Has been Edited";
loadXml();
이제 richTextBox는 정보를 올바르게 표시하지만 저장하지는 않습니다. loadXml()은 데이터 그리드 뷰를 새로 고침하는 방법 중 하나입니다.
나는 완전히 분실했고 어디로 향할 지 모른다. 내 코딩은 probarely 끔찍한 알아, 롤. 나는 이것에 처음이에요. 이것은 제가 작업 한 첫 번째로 복잡한 애플리케이션입니다.
더 이상 내 뜻을 이해하는 데 도움이되는 정보를 생각할 수 없습니다. 니가하길 바래.
도움을 주셔서 대단히 감사합니다.