Get Value In Between Other Values / Get Value between HTML Tags

Used this on Black Friday 2010 to scrape Buy.com’s site for a Plasma deal.


        public void CheckPrice()
        {

            try
            {
                string buyDotComRawScrapeInput = GetScreenScrape("http://www.buy.com/prod/panasonic-tc-p42u2-42-widescreen-1080p-plasma-hdtv-2-000-000-1/q/loc/111/214680105.html");

                string start = @"<span id=""spanMainTotalPrice"" style=""font-size:16px; font-weight:bold;"">";
                string end = "</span>";

                int startNum = buyDotComRawScrapeInput.IndexOf(start);
                int endNum = buyDotComRawScrapeInput.IndexOf(end, startNum);

                string result = buyDotComRawScrapeInput.Substring(startNum + start.Length, endNum - startNum - start.Length);

                if (!string.IsNullOrEmpty(result))
                {
                    if (float.Parse(result) < 450)
                    {
                        // Price is under $400 lets alert!
                        System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
                        myPlayer.SoundLocation = @"c:\windows\media\notify.wav";
                        myPlayer.PlayLooping();

                        SendEmail(result);

                        timer1.Enabled = false;

                    }
                }
            }
            catch (Exception)
            {


            }


        }

How To Pass Back Your Own Object From An Event Call

DebriefDialogResult.cs (New class that inherits from EventArgs

namespace com.aep.ehap.ui
{
    /// <summary>
    /// JHA result from Debrief Dialog
    /// </summary>
    public class DebriefDDialogResult : EventArgs
    {

        /// <summary>
        /// Gets or sets the jha.
        /// </summary>
        /// The jha.
        public JobHazardAnalysis JHA { get; set; }
    }
}

DebriefFeedback.ascx.cs (Code Behind to DebriefFeedback.ascx) which sits in ViewJHA.aspx

 public partial class DebriefFeedback : System.Web.UI.UserControl
    {
        /// <summary>
        /// Occurs when [debrief feedback added].
        /// </summary>
        public event DebriefFeedbackAddedHandler DebriefFeedbackAdded;

        /// <summary>
        /// Delegate for DebriefFeedbackAddedHandler
        /// </summary>
        public delegate void DebriefFeedbackAddedHandler(object sender, DebriefDDialogResult e);

		
		/// <summary>
        /// Handles the Click event of the wibSendFeedback control.
        /// </summary>
        /// The source of the event.
        /// The  instance containing the event data.
		 protected void wibShareYourComment_Click(object sender, Infragistics.WebUI.WebDataInput.ButtonEventArgs e)
        {
		...
		..
		.
		
		  DebriefFeedbackAddedHandler handler = DebriefFeedbackAdded;
          if (handler != null)
              handler(this, new DebriefDDialogResult() { JHA = this.JobHazardAnalysis });
		
		}

ViewJHA.aspx.cs


protected void Page_Load(object sender, EventArgs e)
        {

// Wire up event for DebriefFeedbackAdded            
            this.ctrlDebriefFeedback.DebriefFeedbackAdded += new DebriefFeedback.DebriefFeedbackAddedHandler(ctrlDebriefFeedback_DebriefFeedbackAdded);

}


        void ctrlDebriefFeedback_DebriefFeedbackAdded(object sender, DebriefDDialogResult e)
        {
            // Wire up Review JHA Control from altered JHA in Debrief Comment control
            if (e.JHA != null)
            {

                ctrlReviewJHACtrl.JobHazardAnalysis = e.JHA;
                ctrlReviewJHACtrl.ReviewContext = false;
                ctrlReviewJHACtrl.BindControl();
              
            }
        }