My problem is with a XML file that resides on my windows 2003 web server.
I have this user control which I include on every page in my applicaiton.
The control makes it possible for the users to leave feedback when using the page.
The feedback is written to a XML file which I have put in a folder "C:/Save/".
I've set the access rights on this folder so that the "IUSR_MachineName" has full rights on this folder and it's children.
The "c:/save" folder is included as a virutal folder in the application i.e. /webApplciation/save
All this works fine. The coments are saved along with some other information from server variables.
I've tested and I can both leave a comment and read the given comments in the xml file.
The problem is when I've left the computer running for a while the XML file mysteriously disappears.
Any ideas? I wonder if this is due to some sequrity settings ont win2003 server that I'm not avare of?
I've included the control code and XML file below.
cheers,
mortb
-------------------------------------------------------------------------------------------------------------------------------
leaveComment.ascx:
<%@ Control language="c#" Codebehind="leaveComment.ascx.cs" AutoEventWireup="false" Inherits="controls.leaveComment" %>
<asp:LinkButton ID="_lnkShowComments" Runat="server">Give feedback...</asp:LinkButton>
<asp:LinkButton ID="_lnkHideComments" Runat="server" Visible="False" EnableViewState="False">Hide</asp:LinkButton>
<br>
<asp:TextBox id="_txtComments" runat="server" Height="159px" Width="421px" Visible="False" EnableViewState="False" TextMode="MultiLine"></asp:TextBox>
<br>
<asp:Button ID="_btnAddComment" Text="Submit" Runat="server" Visible="False" />
<asp:Label id="lblThx" runat="server" Visible="False"><h3>Thank you!</h3></asp:Label>
--------------------------------------------------------------------------------------------------------------------------------
leaveComment.ascx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace controls
{
public class leaveComment : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Button _btnAddComment;
protected System.Web.UI.WebControls.Label lblThx;
protected System.Web.UI.WebControls.LinkButton _lnkShowComments;
protected System.Web.UI.WebControls.LinkButton _lnkHideComments;
protected System.Web.UI.WebControls.TextBox _txtComments;
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this._lnkShowComments.Click += new System.EventHandler(this._lnkShowComments_Click);
this._lnkHideComments.Click += new System.EventHandler(this._lnkHideComments_Click);
this._btnAddComment.Click += new System.EventHandler(this._btnAddComment_Click);
}
#endregion
private void _btnAddComment_Click(object sender, System.EventArgs e)
{
XmlDocument oXml = new XmlDocument();
oXml.Load(Server.MapPath("/webApplciation/save/comments.xml"));
XmlNode oNode = oXml.SelectSingleNode("/xml/comments");
XmlElement elem = oXml.CreateElement("comment");
XmlAttribute oAttPage = oXml.CreateAttribute("page");
oAttPage.Value = Server.UrlEncode(Request.Path) ;
elem.Attributes.Append(oAttPage);
XmlAttribute oAttQString = oXml.CreateAttribute("QueryString");
oAttQString.Value = Server.UrlEncode(Request.QueryString.ToString());
elem.Attributes.Append(oAttQString);
/*
XmlAttribute oAttForm = oXml.CreateAttribute("Form");
oAttForm.Value = Request.Form.ToString();
elem.Attributes.Append(oAttForm);
*/
XmlAttribute oDate = oXml.CreateAttribute("time");
oDate.Value = Server.UrlEncode(System.DateTime.Now.ToString());
elem.Attributes.Append(oDate);
elem.InnerText = _txtComments.Text;
oNode.AppendChild(elem);
oXml.Save(Server.MapPath("/webApplciation/save/comments.xml"));
_btnAddComment.Visible = false;
_txtComments.Visible = false;
lblThx.Visible = true;
}
private void _lnkShowComments_Click(object sender, System.EventArgs e)
{
_lnkHideComments.Visible =
_txtComments.Visible =
_btnAddComment.Visible = true;
_lnkShowComments.Visible = false;
}
private void _lnkHideComments_Click(object sender, System.EventArgs e)
{
_lnkShowComments.Visible = true;
_lnkHideComments.Visible =
_txtComments.Visible =
lblThx.Visible =
_btnAddComment.Visible = false;
}
}
}
--------------------------------------------------------------------------------------------------------------------------
comments.xml:
<?xml version="1.0" encoding="utf-8"?>
<xml>
<comments>
</comments>
</xml>