// 仅根据 path 和 ContentFile 读取文件 public async Task <bool> LoadFromFile() { var Folder = await StorageFolder.GetFolderFromPathAsync(Path.GetDirectoryName(path)); if (Folder == null) { return(false); } var File = await Folder.GetFileAsync(Path.GetFileName(path)); if (File == null) { return(false); } var _ContentFile = await Folder.GetFileAsync(ContentFile); if (_ContentFile == null) { return(false); } TimeStamp.Clear(); string FileContent; using (Stream file = await File.OpenStreamForReadAsync()) { using (StreamReader read = new StreamReader(file)) { FileContent = read.ReadToEnd(); } } using (StringReader strRdr = new StringReader(FileContent)) { //通过XmlReader.Create静态方法创建XmlReader实例 using (XmlReader rdr = XmlReader.Create(strRdr)) { //循环Read方法直到文档结束 while (rdr.Read()) { //如果是开始节点 if (rdr.NodeType == XmlNodeType.Element) { //通过rdr.Name得到节点名 string elementName = rdr.Name; if (elementName == "Url") { //读取到节点内文本内容 if (rdr.Read()) { //通过rdr.Value获得文本内容 Url = rdr.Value; } } if (elementName == "ContentFile") { if (rdr.Read()) { if (string.Compare(ContentFile, rdr.Value) != 0) { Debug.WriteLine("读取的内容和保存的内容不符合"); } } } if (elementName == "TimeStampItem") { if (rdr.Read()) { TimeStamp.Add(DateTime.ParseExact(rdr.Value, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)); } } } } } } using (Stream file = await _ContentFile.OpenStreamForReadAsync()) { using (StreamReader read = new StreamReader(file)) { Content = read.ReadToEnd(); } } return(true); }