问题描述
点击新闻"添加"按钮 提示路径不是合法的形式。更新、编辑、删除功能都是正常的.//添加新条目privatevoidButton2_Click(objectsender,System.EventArgse){if(this.IsValid){try{stringtitle=this.txtTitle2.Text;stringcontent=this.txtContent2.Text;//xmlPath=Server.MapPath("./")+MyXml.strXmlPath+"news.xml";myxml=newMyXml(xmlPath);XmlDocumentxDoc=myxml.LoadXmlDoc();XmlNodexRoot,xNode;xRoot=xDoc.GetElementsByTagName("informations")[0];//XmlAttributeAttri,id,time;//节点属性id=xDoc.CreateAttribute("id");Attri=xDoc.CreateAttribute("title");time=xDoc.CreateAttribute("time");Attri.Value=title;id.Value=xDoc.SelectNodes("//information").Count.ToString();time.Value=DateTime.Now.ToString();xNode=xDoc.CreateElement("information");xNode.InnerText="n"+content+"n";xNode.Attributes.Append(id);xNode.Attributes.Append(Attri);xNode.Attributes.Append(time);xRoot.AppendChild(xNode);xDoc.Save(myxml.URL);//Page.RegisterStartupScript("refresh","<script>alert("提交成功!");location.href="information.aspx";</script>");}catch(System.Xml.XmlExceptionex){thrownewException(ex.Message);}}}
解决方案
解决方案二:
还是检查下文件路径问题吧