Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 19th, 2009, 11:13 PM
Registered User
 
Join Date: Nov 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Contact form From Chapter 9

Hello,
I am just started learning Asp.net with C#. I had created a contact form following instruction from the book and I did successfully locally however now when I tested live using one of the free web hosting, it doesn't work. I have no idea why as I totally new to this. I have been spending day and night on this error and can't move on any further so if you could help me with this I would be the happiest person in the whole world.

Thank you very much in anticipation.
Following is the error I got and the code in ContactForm.ascx.cs

Error
Could not find file 'C:\sites\content\App_Data\ContactForm.txt'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.FileNotFoundException: Could not find file 'C:\sites\content\App_Data\ContactForm.txt'.

Source Error:
Line 38: {
Line 39: string fileName= Server.MapPath("~/App_Data/ContactForm.txt");
Line 40: string mailBody = System.IO.File.ReadAllText(fileName);
Line 41:
Line 42: mailBody = mailBody.Replace("##Name##", txtName.Text);


ContactForm.ascx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Net.Mail;

public partial class Controls_ContactForm : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (txtPhoneHome.Text != string.Empty || txtMobile.Text != string.Empty)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}

protected void btnSend_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string fileName= Server.MapPath("~/App_Data/ContactForm.txt");
string mailBody = System.IO.File.ReadAllText(fileName);

mailBody = mailBody.Replace("##Name##", txtName.Text);
mailBody = mailBody.Replace("##Email##", txtEmailAddress.Text);
mailBody = mailBody.Replace("##HomePhone##", txtPhoneHome.Text);
mailBody = mailBody.Replace("##BusinessPhone##", txtMobile.Text);
mailBody = mailBody.Replace("##Comments##", txtComments.Text);

MailMessage myMessage = new MailMessage();
myMessage.Subject = "Response from web site";
myMessage.Body = mailBody;

myMessage.From = new MailAddress("[email protected]", "Sender Name Here");
myMessage.To.Add(new MailAddress("[email protected]", "Receiver Name Here"));

SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);

lblMessage.Visible = true;
FormTable.Visible = false;
PlaceHolder1.Visible = false;
Heading.Visible = false;


}
}
}
 
Old November 20th, 2009, 04:35 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Are you really sure the App_Data folder is on your live server and contains the requested text file? How do you upload your files? Is there a way for you to see your files on-line and check if they are all there?

Otherwise, you may need to talk to your host. Maybe they blocked access to some functionality or files....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
susu2009 (November 20th, 2009)
 
Old November 20th, 2009, 08:44 AM
Registered User
 
Join Date: Nov 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Contact Form

Hi Imar,
First of all thank you very much for your instant reply.
Yes, I am very sure that App_Data folder is on my live server and it contains the text file.
I used http://www.brinkster.com/ for the free hosting and I upload files exactly the same folder structure as in Chapter 9 folder. I have created folders and put the files to the folder which it belongs. I just think that this is has to do with the free hosting.

Now I going to get a paid hosting and see what happens.
Thank you for help and I have to say that your book is a brilliant book.
 
Old November 20th, 2009, 08:49 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome. Hope it works out fine.

Are you moving the site just for this? If so, it's worth contacting Brinkster support (generally pretty fast and knowledgeable) and see if they can help you out.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
I need help with contact form iorgusu Need help with your homework? 1 September 27th, 2009 01:56 AM
Contact form? philthy BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 1 July 23rd, 2009 05:14 PM
contact form Will BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 6 February 24th, 2009 01:42 PM
Chapter 9 pps 314-316 Contact Form User Control Featheriver BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 February 2nd, 2009 03:19 AM
Contact Form myself Classic ASP Basics 1 November 18th, 2006 11:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.