/// <summary> /// 在此页将要在 Frame 中显示时进行调用。 /// </summary> /// <param name="e">描述如何访问此页的事件数据。 /// 此参数通常用于配置页。</param> async protected override void OnNavigatedTo(NavigationEventArgs e) { EditAppbar.Visibility = Windows.UI.Xaml.Visibility.Visible; AddAppbar.Visibility = Windows.UI.Xaml.Visibility.Visible; FindAppbar.Visibility = Windows.UI.Xaml.Visibility.Visible; DeleteAppbar.Visibility = Windows.UI.Xaml.Visibility.Collapsed; //if (e.Parameter != null) //{ // cityname.city = e.Parameter.ToString(); // cityName.Add(cityname); //} //colCityName.ItemsSource = cityName; Files.Items.Clear(); //创建文件夹 StorageFolder storage = await ApplicationData.Current.LocalFolder.CreateFolderAsync("CityList", CreationCollisionOption.OpenIfExists); //获取当前文件夹中的文件 var files = await storage.GetFilesAsync(); //便利 每一个文件 foreach (StorageFile file in files) { XmlDocument doc=await XmlDocument.LoadFromFileAsync (file ); //cityname.city = doc.DocumentElement.Attributes.GetNamedItem ("city").NodeValue.ToString (); cityname = new Citys(); cityname.city = file.DisplayName; if (cityname.city == "City") continue; else cityName.Add(cityname); } Files.ItemsSource = cityName; }
/// <summary> /// 在此页将要在 Frame 中显示时进行调用。 /// </summary> /// <param name="e">描述如何访问此页的事件数据。 /// 此参数通常用于配置页。</param> async protected override void OnNavigatedTo(NavigationEventArgs e) { EditAppbar.Visibility = Windows.UI.Xaml.Visibility.Visible; AddAppbar.Visibility = Windows.UI.Xaml.Visibility.Visible; FindAppbar.Visibility = Windows.UI.Xaml.Visibility.Visible; DeleteAppbar.Visibility = Windows.UI.Xaml.Visibility.Collapsed; //if (e.Parameter != null) //{ // cityname.city = e.Parameter.ToString(); // cityName.Add(cityname); //} //colCityName.ItemsSource = cityName; Files.Items.Clear(); //创建文件夹 StorageFolder storage = await ApplicationData.Current.LocalFolder.CreateFolderAsync("CityList", CreationCollisionOption.OpenIfExists); //获取当前文件夹中的文件 var files = await storage.GetFilesAsync(); //便利 每一个文件 foreach (StorageFile file in files) { XmlDocument doc = await XmlDocument.LoadFromFileAsync(file); //cityname.city = doc.DocumentElement.Attributes.GetNamedItem ("city").NodeValue.ToString (); cityname = new Citys(); cityname.city = file.DisplayName; if (cityname.city == "City") { continue; } else { cityName.Add(cityname); } } Files.ItemsSource = cityName; }
public async void readXmlFile() { //StorageFile file1 = null; string text; Citys cityname; List<Citys> citys = new List<Citys>(); //var folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("NewFolder"); //foreach (StorageFile file in await folder.GetFilesAsync()) //{ // if (file.Name == "XMLFile.xml") // { // file1 = file; // break; // } //} var file1 = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("CitysXmlFile.xml"); if (file1 == null) return; IRandomAccessStream accesssStream = await file1.OpenReadAsync(); using (StreamReader stream = new StreamReader(accesssStream.AsStreamForRead((int)accesssStream.Size))) { text = stream.ReadToEnd(); } string a = "<string>"; string b = "</string>"; int indexa = 1; int indexb = 1; for (int i = 0; i < text.Length; i++) { indexa = text.IndexOf(a, indexa + 1); indexb = text.IndexOf(b, indexb + 1); if (indexa == -1 && indexb == -1) break; string s = text.Substring(indexa + a.Length, indexb - indexa - a.Length); cityname1 = new Citys(); cityname1.city = s; App.citynameList.Add(cityname1); } }
/// <summary> /// 在此页将要在 Frame 中显示时进行调用。 /// </summary> /// <param name="e">描述如何访问此页的事件数据。 /// 此参数通常用于配置页。</param> async protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter != null) { cityname = new Citys(); cityname.city = e.Parameter.ToString(); App.nearFindCity.Clear(); //读取近期城市文件 StorageFolder storage = await ApplicationData.Current.LocalFolder.CreateFolderAsync("NearCityList", CreationCollisionOption.OpenIfExists); //获取当前文件夹中的文件 var files = await storage.GetFilesAsync(); //遍历每个文件 foreach (StorageFile file in files) { file.DateCreated.ToFileTime(); //XmlDocument doc=await XmlDocument.LoadFromUriAsync (new Uri(file.Path)); //cityname.city = doc.DocumentElement.Attributes.GetNamedItem("city").NodeValue.ToString(); cityname1 = new Citys(); cityname1.city = file.DisplayName; if (cityname1.city == "City") { continue; } else { App.nearFindCity.Add(cityname1); } } if (App.nearFindCity.Count == 0) { App.nearFindCity.Add(cityname); } else { //if(App.nearFindCity.Contains (cityname )==true ) // return; foreach (Citys city5 in App.nearFindCity) { if (city5.city.ToString() == cityname.city.ToString()) { goto loop; } } App.nearFindCity.Add(cityname); if (App.nearFindCity.Count > 3) { do { Random r = new Random(); App.nearFindCity.RemoveAt(r.Next(2)); } while (App.nearFindCity.Count != 3); } } loop: StorageFolder storage1 = await ApplicationData.Current.LocalFolder.CreateFolderAsync("NearCityList", CreationCollisionOption.ReplaceExisting); foreach (Citys cityname2 in App.nearFindCity) { XmlDocument _doc = new XmlDocument(); XmlElement _item = _doc.CreateElement(cityname2.city.ToString()); _doc.AppendChild(_item); StorageFile file1 = await storage1.CreateFileAsync(cityname2.city.ToString() + ".xml", CreationCollisionOption.ReplaceExisting); await _doc.SaveToFileAsync(file1); } } }
/// <summary> /// 在此页将要在 Frame 中显示时进行调用。 /// </summary> /// <param name="e">描述如何访问此页的事件数据。 /// 此参数通常用于配置页。</param> async protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter != null) { cityname = new Citys(); cityname.city = e.Parameter.ToString(); App.nearFindCity.Clear(); //读取近期城市文件 StorageFolder storage = await ApplicationData.Current.LocalFolder.CreateFolderAsync("NearCityList", CreationCollisionOption.OpenIfExists); //获取当前文件夹中的文件 var files = await storage.GetFilesAsync(); //遍历每个文件 foreach (StorageFile file in files) { file.DateCreated.ToFileTime(); //XmlDocument doc=await XmlDocument.LoadFromUriAsync (new Uri(file.Path)); //cityname.city = doc.DocumentElement.Attributes.GetNamedItem("city").NodeValue.ToString(); cityname1 = new Citys(); cityname1.city = file.DisplayName; if (cityname1.city == "City") continue; else { App.nearFindCity.Add(cityname1); } } if (App.nearFindCity.Count == 0) App.nearFindCity.Add(cityname); else { //if(App.nearFindCity.Contains (cityname )==true ) // return; foreach (Citys city5 in App.nearFindCity) { if (city5.city.ToString() == cityname.city.ToString()) goto loop; } App.nearFindCity.Add(cityname); if (App.nearFindCity.Count > 3) { do { Random r = new Random(); App.nearFindCity.RemoveAt(r.Next(2)); } while (App.nearFindCity.Count != 3); } } loop: StorageFolder storage1 = await ApplicationData.Current.LocalFolder.CreateFolderAsync("NearCityList",CreationCollisionOption.ReplaceExisting); foreach(Citys cityname2 in App.nearFindCity ) { XmlDocument _doc = new XmlDocument(); XmlElement _item = _doc.CreateElement(cityname2.city.ToString ()); _doc.AppendChild(_item); StorageFile file1 = await storage1.CreateFileAsync(cityname2.city.ToString() + ".xml", CreationCollisionOption.ReplaceExisting); await _doc.SaveToFileAsync(file1); } } }