日期:2014-05-18  浏览次数:20989 次

急急急!!保存xml文件时,弹框“该文件已在源编辑器之外被修改是否重新加载它??”
#region##将图片保存为xml格式文件
  /// <summary>
  /// 将图片保存为xml格式文件
  /// </summary>
  public void SaveXML(int AlbumId)
  {
  string path = "gallery/Madeira/gallery.xml";
  string pathUrl = Server.MapPath(path);
  FileInfo file = new FileInfo(pathUrl);
   

  System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument(); //加入XML的声明段落
  System.Xml.XmlNode xmlnode = xmldoc.CreateNode(System.Xml.XmlNodeType.XmlDeclaration, "", "");
  xmldoc.AppendChild(xmlnode); //加入一个根元素  
  System.Xml.XmlElement xmlelem = xmldoc.CreateElement("simpleviewerGallery");



  //将每个字段值 追加到XML中
  xmlelem.SetAttribute("maxImageHeight", "1024");
  xmlelem.SetAttribute("maxImageWidth", "1024");
  xmlelem.SetAttribute("textColor", "0xFFFFFF");
  xmlelem.SetAttribute("frameColor", "0xffffff");
  xmlelem.SetAttribute("frameWidth", "20");
  xmlelem.SetAttribute("stagePadding", "40");
  xmlelem.SetAttribute("thumbnailColumns", "3");
  xmlelem.SetAttribute("thumbnailRows", "3");
  xmlelem.SetAttribute("navPosition", "left");
  xmlelem.SetAttribute("title", "Madeira");
  xmlelem.SetAttribute("enableRightClickOpen", "true");
  xmlelem.SetAttribute("navPosition", "left");
  xmlelem.SetAttribute("backgroundImagePath", "left");
  xmlelem.SetAttribute("thumbPath", "images/");
  xmlelem.SetAttribute("imagePath", "images/");
  xmldoc.AppendChild(xmlelem);




  System.Collections.Generic.List<LiaoJieWebModels.Photo> list = LiaoJieWebBLL.PhotoManager.GetPhotoByAlbumId(AlbumId);
  foreach (LiaoJieWebModels.Photo photo in list)
  {
  System.Xml.XmlElement xmlelem1 = xmldoc.CreateElement("", "image", "");
  xmlelem.AppendChild(xmlelem1);

  System.Xml.XmlElement xmlelem2 = xmldoc.CreateElement("", "filename", "");
  System.Xml.XmlText xmltext2 = xmldoc.CreateTextNode(photo.PhotoUrl);
  xmlelem2.AppendChild(xmltext2);
  xmlelem1.AppendChild(xmlelem2);

  System.Xml.XmlElement xmlelem3 = xmldoc.CreateElement("", "caption", "");
  System.Xml.XmlText xmltext3 = xmldoc.CreateTextNode(photo.PhotoName);
  xmlelem3.AppendChild(xmltext3);
  xmlelem1.AppendChild(xmlelem3);
  }
  try
  {

  if (file.Exists)
  file.Delete();
  xmldoc.Save(pathUrl);
  }
  catch (Exception e)
  { //显示错误信息 
  Console.WriteLine(e.Message);
  }
  Console.ReadLine();
  }
  #endregion

------解决方案--------------------
帮顶。。。。
------解决方案--------------------
你的工程文件被VS打开了两次,一个修改了文件,另一个就会报这个错。
或者,你工程文件用vs