Run time errors with DataGrid

S

Stephen Cairns

I am trying to create a guest book in a web application
and I keep getting the following runtime error:
Access to the
path "c:\inetpub\wwwroot\Guestbook\guestbook.txt" is
denied.

guestbook.txt is part of my solution so im not sure what
the problem is. Can anyone help me please. The code is
below: -


private void Page_Load(object sender, System.EventArgs e)
{
dataView = new DataView(new DataTable() );
}
public void FillMessageTable()
{
DataTable table = dataView.Table;
table.Columns.Add("Date");
table.Columns.Add("First Name");
table.Columns.Add("e-mail");
table.Columns.Add("Message");

//open guest book file for reading
StreamReader reader = new StreamReader(
Request.PhysicalApplicationPath +
"guestbook.txt");

char[] separator = {'\t'};
//read in line from file
string message = reader.ReadLine();

while (message != null)
{
//split the string into its four parts
string[] parts = message.Split(separator);

//load data into table
table.LoadDataRow(parts, true);

//read in one line from file
message = reader.ReadLine();
}

//update grid
dataGrid.DataSource = table;
dataGrid.DataBind();
reader.Close();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{

//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.clearbutton.Click += new System.EventHandler
(this.clearbutton_Click);
this.submitbutton.Click += new System.EventHandler
(this.submitbutton_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

private void submitbutton_Click(object sender,
System.EventArgs e)
{
StreamWriter guestbook =
new StreamWriter(Request.PhysicalApplicationPath +
"guestbook.txt", true);

//write new message to file
guestbook.WriteLine(
DateTime.Now.Date.ToString().Substring(0, 10) +
"\t" + nameTextBox.Text + "\t" + emailTextBox.Text
+ "\t" + messageTextBox.Text );

//clear textboxes and close stream
nameTextBox.Text = "";
emailTextBox.Text = "";
messageTextBox.Text = "";
guestbook.Close();

FillMessageTable();
}
 
S

Simon Smith

I am trying to create a guest book in a web application
and I keep getting the following runtime error:
Access to the
path "c:\inetpub\wwwroot\Guestbook\guestbook.txt" is
denied.

guestbook.txt is part of my solution so im not sure what
the problem is. Can anyone help me please. The code is
below: -

Quite probably the user that ASP.NET is running as does not have permissions
to write to the file. Check the security on it (on the deployment machine)
and make sure that the ASP.NET process username is included.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top