473,382 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

DataGrid Run-time Error

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();
}
Nov 16 '05 #1
0 887

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Luna | last post by:
Hi I wanted to ask anyone if they have done anything silimar to this.. I have the following code to highlight the entire row when any cell of the datagrid is clicked.. Private Sub...
2
by: Craig S | last post by:
I believe the problem is definately a lack of understanding on my part about how postbacks work, but here goes... In my Page_Load method I bind my data from a SQL database to a datagrid - works...
3
by: Quetzal | last post by:
Hello, I have a dataset populated using an XML file. The schema has hierarchical components. Let's say <a><b></b></a>. I have created a datagrid and I have assigned a datastyle and then...
3
by: Hoodworld | last post by:
Hi All, I have a ASP.Net application written in C# with the use of Visual Studio 2003. When I develop and test the application in my company using ASP.Net Framework 1.4.33.2 in Windows XP...
1
by: Rick White | last post by:
I have an asp.net page on which I have a datagrid. The datagrid works exactly as I want up to this point: I want to have a pushbutton on the datagrid that will cause the selected row to a...
2
by: Mark Rae | last post by:
I've inherited an ASP.NET app and have been asked to fix the following problem with a page which is used to display and/or delete records from a database. When the page loads, it displays a list of...
5
by: John M | last post by:
Hello, In Visual Studio .NET 2003, How can I change the columns' width (at design or runtime) of datagrid ? Thanks :)
5
by: Jeff User | last post by:
Hello ..NET 1.1, VS 2003, C# & asp.net I have tried to follow msdn instructions and samples but I can not get an event to fire for this button on the datagrid. There has to be something obvious...
2
by: Cindy | last post by:
Hello. For some reason, I am able to "connect" to the Northwind database whenever I use the wizard; however, when I run the application, my datagrid does not display. Here are the exact steps I...
0
by: arlie_maija | last post by:
Hey - I'm writing a control that contains a DataGrid, and I'm unable to get the update event to fire. When I click the update link, the edit event fires. heres the details... my control...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.