Duckduckgo

using AngleSharp.Dom;
using AngleSharp.Html.Dom;
using AngleSharp.Html.Parser;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string Title { get; set; }
private string Url { get; set; }

private string siteUrl = “https://duckduckgo.com/lite?q=” + “\”@applozic.com email”;
public string[] QueryTerms { get; } = { “Ocean”, “Nature”, “Pollution” };

internal async void ScrapeWebsite()
{
CancellationTokenSource cancellationToken = new CancellationTokenSource();
HttpClient httpClient = new HttpClient();
HttpResponseMessage request = await httpClient.GetAsync(siteUrl);
cancellationToken.Token.ThrowIfCancellationRequested();

Stream response = await request.Content.ReadAsStreamAsync();
cancellationToken.Token.ThrowIfCancellationRequested();

HtmlParser parser = new HtmlParser();
IHtmlDocument document = parser.ParseDocument(response);
GetScrapeResults(document);
}
private void button1_Click(object sender, EventArgs e)
{
ScrapeWebsite();
}

private void GetScrapeResults(IHtmlDocument document)
{
IEnumerable<IElement> articleLink;
string dd = document.Body.InnerHtml;
textBox1.Text = dd;
foreach (var term in QueryTerms)
{
articleLink = document.All.Where(x => x.ClassName == “views-field views-field-nothing” && (x.ParentElement.InnerHtml.Contains(term) || x.ParentElement.InnerHtml.Contains(term.ToLower())));
}

//if (articleLink.Any())
//{
// // Print Results: See Next Step
//}
}
}
}

sample code of Out parameter in c#

in Out parameter no need to assign the value before passing.

but in Ref Parameter you must have to assign the value before passing .

see the gender variable in this code

See the sample code for OUT parameter

 

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

{
string Gender;
string printValue;

//some class properties assignment
clsAll objEmployeedetails = new clsAll();
objEmployeedetails.Name = “tarun”;
objEmployeedetails.age = 25;
objEmployeedetails.Address = “This is the address”;

//calling function
printproperties(objEmployeedetails,out Gender);

printValue=string.Format(“Gender Value after calling the function is {0}”,Gender.ToUpper());
Response.Write(printValue);
}

private void printproperties(clsAll getEmployeeDetails,out string gender)
{
//Assigning the value in Gender Variable here
gender = “female”;

}
}

 

 

So output will be 

Gender Value after calling the function is FEMALE

Create Your Own Exception Class [C#,Asp.net]

In some bigger application we used to create our own exception class.

i have written one example have a look on it

public class ClsTarunException : ApplicationException
{

//These are Class Properties
private DateTime _TimeOccured;
private String _Reason;
private String _Message;

public DateTime TimeOccured
{
get { return _TimeOccured; }
set { _TimeOccured = value; }
}

public String Reason
{
get { return _Reason; }
set { _Reason = value; }
}

public override string Message
{
get { return _Message; }
// set { _Message = value; }
}

//Here is the constructor
public ClsTarunException()
{
//No Parameter constructor
}
public ClsTarunException(string message, string cause, DateTime time)
{
//Constructor with parameter
_Message = message;
_Reason = cause;
_TimeOccured = time;

}

}

 

 

 

And this the Page where i am using this exception class

public partial class TarunException : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
//This function will throw the exception
throwMyError();
}
catch (ClsTarunException ex)
{
Response.Write(string.Format(“This is the message—-{0}”,ex.Message));
Response.Write(string.Format(“<br>This is the Time when exception occured —{0}”, ex.TimeOccured));
Response.Write(string.Format(“<br>This is the reason why the exception occured —-{0}”, ex.Reason));
}
}

private void throwMyError()
{
ClsTarunException Excep = new ClsTarunException(“My tank Is full”, “i was eating like a big Elephant”, DateTime.Now);
throw Excep;
}
}

 

 

 

See here is the Output on page load

This is the message—-My tank Is full
This is the Time when exception occured —12/19/2012 7:23:34 PM
This is the reason why the exception occured —-i was eating like a big Elephant