TreeView控件TreeNodeSrc="org.xml"绑定文件不能更新问题

csdncb 2005-03-31 05:01:28
我在asp.net(C#)的webform上放了一个ie controls中的TreeView控件,其中:
(1)TreeView控件的节点treenode从org.XML一文件中绑定得到,显示正常
(2)页面放有一控件(btnAdd),操作内容,先将新节点添加到xml文件中,然后从新绑定treeView控件。确总是得到“进程无法访问,因为另一个程序正在使用此文件”的错误提示?为什么
页面的绑定代码如下:
<iewc:TreeView id="TreeView1" runat="server"Height="400px" Width="250px" Expanded="True">
<treenode Text="root" type="tree" TreeNodeSrc="../Company/comltd/cache/org.xml" ></treenode>
</iewc:TreeView>
相关代码如下:
(3)Page Load:
UserSessionInfo usi=(UserSessionInfo)Session["SessionUser"];
cachePath=SMGlobals.instance().getCompanyCatcheDir(usi.CompanyID)+"org.xml";
if(!Page.IsPostBack)
{
  this.TreeView1.TreeNodeSrc=cachePath+"?"+DateTime.Now.Ticks;
TreeView1.DataBind();
}
(4)BtnAdd事件
 comfile.AddXmlNode(cachePath,"",this.TextBox2.Text,this.TextBox3.Text);
 this.TreeView1.TreeNodeSrc=cachePath;
 TreeView1.DataBind();
(5)添加节点的方法:
public static void AddXmlNode (string sFilePath,string KeyParent,string KeyChild,string TextChild)
{
XmlDocument xmlDoc = new XmlDocument();
XmlNode refNode=null;
try
{
xmlDoc.Load(sFilePath);
XmlElement newNode=xmlDoc.CreateElement("treenode");
XmlAttribute attNode=xmlDoc.CreateAttribute("text");
attNode.Value=TextChild;
newNode.Attributes.Append(attNode);
attNode=xmlDoc.CreateAttribute("id");
attNode.Value=KeyChild;
newNode.Attributes.Append(attNode);

if(KeyParent.Trim()!="")
{
refNode=xmlDoc.GetElementById(KeyParent);
refNode.AppendChild(newNode);
}
else
{
refNode=xmlDoc.GetElementsByTagName("TREENODES").Item(0) ;
if(refNode!=null)
{
refNode.AppendChild(newNode);
}
else
{
xmlDoc.AppendChild(newNode);
}
}

//xmlDoc.InsertAfter(newNode,refNode);
//xmlDoc.AppendChild(newNode);

xmlDoc.Save(sFilePath);
}
catch(Exception e1)
{
string a=e1.Message;
}
}

谢谢各位相助!
我得到是结论:因为asp.缓存中包括了控件所使用的xml文件,所以不能更新
我试验是过程:如何将treenodesrc属性去掉,而使用<include file="...">的方式,是可以更新文件的?

请问,咱的问题如何解决?





...全文
161 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
csdncb 2005-04-13
  • 打赏
  • 举报
回复
?
csdncb 2005-04-08
  • 打赏
  • 举报
回复
谢谢athossmth(athos)!
不过,我不想这样做,希望能得到更简单的方案。
athossmth 2005-04-07
  • 打赏
  • 举报
回复
解决办法是使用动态的页面产生xml内容。具体做法,以及你这样做失败的原因见
《分享:IE Webcontrols Treeview的一个bug及修正(athossmth)》
http://community.csdn.net/Expert/TopicView.asp?id=3807434
ziyan0218 2005-04-07
  • 打赏
  • 举报
回复
mark
lstup 2005-04-05
  • 打赏
  • 举报
回复
扑通。帮定
mymyal123 2005-04-05
  • 打赏
  • 举报
回复
学习
csdncb 2005-04-05
  • 打赏
  • 举报
回复
?

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧