Here is my issue. I'm attempting to create a daily mailing using a console app. Well, when I started, I for some brilliant reason made a web app. So I'm trying to translate it into a console app, and while I THINK this should work, I keep getting a "type or namespace definition, or end-of-file expected" immediately following my static Main. It looks to me as if I have all of my brackets accounted for, but it's not reading it for some reason. It's a pretty simple app, but I'm also pretty new at this.

Can anybody:

A. Explain why I'm getting this error and/or tell me how to fix it;
B. Point out anything blatant that I might be missing?

I'd really appreciate any help anyone can give me.

using System;
using System.IO;
using System.Net;
using System.Net.Mail;
using System.Web.UI;


namespace Daily_Mailing
{
    class Program
    {
        static void Main(string[] args)        
        {
             public partial class _Default : System.Web.UI.Page
             {
                protected void Page_Load(object sender, EventArgs e)
                {
                    SmtpClient smtpClient = new SmtpClient();
                    MailMessage message = new MailMessage();

                    try
                    {
                        MailAddress fromAddress = new MailAddress("Admin@mywebsite.com", "Admin");
                        message.From = fromAddress;
                        message.To.Add("ME@mywebsite.com");
                        message.Subject = "Test";
                        message.CC.Add("ME@mywebsite.com");
                        
                        string html = ScreenScrapeHtml("sourcewebsite.aspx");
                        message.Body = html;
                        message.IsBodyHtml = true;

                        smtpClient.Send(message);
                    }
                    catch (Exception)
                    {

                    }
                }
                public static string ScreenScrapeHtml(string url)
                {
                    WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
                    StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream());
                    string result = sr.ReadToEnd();
                    sr.Close();
                    return result;
                }
             
             }
        }

    }
    
}
}

Also, I might have needed to put this in the C# forum, so I can move this if needed.

What line are you getting the error? Line 43?

It's actually on Line 13, it tells me that that Main needs a closing }. So I tore the whole thing apart in hopes that I just misplaced the }, and pasted each part in piece by piece, and all the brackets did line up, but it still returned that particular error.

I had modified your code a little just to fix some issues... I did not debug your scraping method.

using System;
using System.IO;
using System.Net;
using System.Text;
using System.Net.Mail;
using System.Web.UI;

namespace Daily_Mailing
{
    class Program
    {
        public partial class _Default : System.Web.UI.Page { }
        static void Main(string[] args)
        {
            runMe();
        }
        public static void runMe()
        {
            SmtpClient smtpClient = new SmtpClient();
            MailMessage message = new MailMessage();
            try
            {
                MailAddress fromAddress = new MailAddress("Admin@mywebsite.com", "Admin");
                message.From = fromAddress;
                message.To.Add("ME@mywebsite.com");
                message.Subject = "Test";
                message.CC.Add("ME@mywebsite.com");
                string html = ScreenScrapeHtml("http://www.daniweb.com/forums/thread266510.html");
                message.Body = html;
                message.IsBodyHtml = true;
                smtpClient.Send(message);
            }
            catch (Exception e)
            {
                Console.Write(e.Message);
            }
        }
        public static string ScreenScrapeHtml(string url)
        {

            WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
            StreamReader sr = new StreamReader(objRequest.GetResponse().GetResponseStream());
            string result = sr.ReadToEnd();
            sr.Close();
            return result;

        }
    }
}

HTH's

Awesome, thanks for the help! That's great!

Awesome, thanks for the help! That's great!

No Problem!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.