每次都要提示“该文件在原编辑器之外修改 是否要重新加载它”怎么解决???
源码: private void SaveXMLData()
{
string path = Server.MapPath(".") + "/gallery.xml";
XmlTextWriter textWriter = new XmlTextWriter(path, System.Text.Encoding.UTF8);
textWriter.Formatting = Formatting.Indented;//自动缩进
textWriter.WriteStartDocument();// 开始写过程,调用WriteStartDocument方法
textWriter.WriteComment("注释");// 写入注释
textWriter.WriteStartElement("gallery");//写根节点
textWriter.WriteStartElement("setup");
textWriter.WriteElementString("imgPath", "images/文物/");//----图片路
textWriter.WriteElementString("imgCaptionColor", "0xFFFFFF");
textWriter.WriteElementString("imgCaptionSize", "10");
textWriter.WriteElementString("imgCaptionAlpha", "0.7");
textWriter.WriteElementString("imgCaptionPosition", "bottom");
textWriter.WriteElementString("imgCaptionBgColor", "0x000000");
textWriter.WriteElementString("imgCaptionBgAlpha", "0.7");
textWriter.WriteElementString("backgroundImgPath", "images/bg.jpg");
textWriter.WriteElementString("backgroundImgAlpha", "1");
textWriter.WriteEndElement();//setup节点结束
string picPath="69/[文物]"+ViewState["文物_ID"].ToString()+"-";
int picNUm = 4;//----------------------------------------------------------------------
for (int i = 1; i < picNUm+1; i++)
{
textWriter.WriteStartElement("item");//创建节点
textWriter.WriteElementString("thumb",picPath+i.ToString()+".jpg");//节点元素
textWriter.WriteElementString("img", picPath + i.ToString() + ".jpg");
textWriter.WriteElementString("caption", picPath + i.ToString() + ".jpg");
textWriter.WriteEndElement();//节点结束
}
textWriter.Flush();//------------------------------刷新
textWriter.WriteEndElement();//根节点结束
textWriter.Flush();//------------------------------刷新
textWriter.WriteEndDocument();//写文档结束,调用WriteEndDocument方法
textWriter.Flush();//------------------------------刷新
textWriter.Close(); //关闭textWriter
}
只要不在VS里打开这个XML文件,就不会收到提示的。
lz是否使用多个编辑工具打开了该文件?关闭其他的编辑器即可