Monday, June 23, 2014

Dealing with MS SQL Tables that contain Duplicate Rows — DatabaseJournal.com

Dealing with MS SQL Tables that contain Duplicate Rows

By Gregory A. Larsen

Every so often, you might have to deal with tables that contain duplicate rows. In one case, you might only need to identify the duplicate rows. In other cases, you might need to remove the duplicate rows. This article will show you some different techniques for dealing with duplicate rows.

c# - Use ListForEach to add element to HashTable - Stack Overflow
Try this:
valueList.ForEach(x => htable.Add(valueList.FindIndex(y => y == x), x));
Although, there's really no reason not to use a for here
for(var index =0; index < valueList.Count; index++){
    htable.Add(index, valueList[index]);}

xml - What is the correct XPath for choosing attributes that contain "foo"? - Stack Overflow

The link above is quite interesting for HTMLAgilityPack C# beginners, helps a lot !

Another thing to note is that while the XPath above will return the correct answer for that particular xml, if you want to guarantee you only get the "a" elements in element "blah", you should as others have mentioned also use

/bla/a[contains(@prop,'Foo')]

This will search you all "a" elements in your entire xml document, regardless of being nested in a "blah" element

//a[contains(@prop,'Foo')]

Check out the link for more information

Html Agility Pack - Problem selecting within a node

Recommended Tags for Documentation Comments (C# Programming Guide)

The C# compiler processes documentation comments in your code and formats them as XML in a file whose name you specify in the /doc command-line option. To create the final documentation based on the compiler-generated file, you can create a custom tool, or use a tool such as Sandcastle.

Here are some Recommended Tags for Documentation Comments

<c>

<para>

<see>*

<code>

<param>*

<seealso>*

<example>

<paramref>

<summary>

<exception>*

<permission>*

<typeparam>*

<include>*

<remarks>

<typeparamref>

<list>

<returns>

<value>

(C# Programming Guide)

The <summary> tag should be used to describe a type or a type member. Use <remarks> to add supplemental information to a type description. Use the cref Attribute to enable documentation tools such as Sandcastle to create internal hyperlinks to documentation pages for code elements.

The text for the <summary> tag is the only source of information about the type in IntelliSense, and is also displayed in the Object Browser Window.

Compile with /doc to process documentation comments to a file. To create the final documentation based on the compiler-generated file, you can create a custom tool, or use a tool such as Sandcastle.

Thursday, June 19, 2014

Explicit cast:

int x =0;float y =3.8f;

x +=(int) y;//Explicit cast.

This tells the compiler that the cast was intentional and that you know that the fractional part will go lost. The compiler won't complain.

Implicit cast:

int x =0;float y =3.8f;

x += y;//Implicit cast

The compiler will complain because the fractional part will be lost when converting float to int.

c# - What is the difference between explicit and implicit type casts? - Stack Overflow

Explicit cast:

int x =0;float y =3.8f;

x +=(int) y;//Explicit cast.

This tells the compiler that the cast was intentional and that you know that the fractional part will go lost. The compiler won't complain.

Implicit cast:

int x =0;float y =3.8f;

x += y;//Implicit cast

The compiler will complain because the fractional part will be lost when converting float to int.

Visual Studio 2013

The explicit keyword declares a user-defined type conversion operator that must be invoked with a cast. For example, this operator converts from a class called Fahrenheit to a class called Celsius:

explicit (C# Reference)

c# - What is the difference between explicit and implicit type casts? - Stack Overflow

What is the difference between explicit and implicit type casts?

What's the difference between the President of the United States and the President of Canada?

Since there is no President of Canada, it's hard to answer the question. The right thing to do is to push back and ask for clarification of the question. By "the President of Canada", does the questioner mean the Queen (ceremonial head of state), the Governor General (who can veto bills) or the Prime Minister (who effectively acts as the executive), or something else? Hard to say without clarification.

And even with clarification, it's a vague question. What differences do you want to know about?

Since there is no such thing as an "implicit cast" in C# it is hard to answer your question. In C#, casting is an operator. So I'll push back on it.

Did you mean to ask "what's the difference between an explicit conversion and an implicit conversion?" Or did you mean to ask about the semantics of the cast operator? Or the difference between the cast operator and other type conversion operators? Or situations in which cast operators can be "implicitly" inserted into your code by the compiler? (For example, the foreach loop and the += operator can both implicitly insert an invisible cast.)

Friday, June 13, 2014

In beginning coding in C# DotNet, we usually come across such errors, and it's good to look into them, see link below for more details

c# - httpWebRequest (The underlying connection was closed: The connection was closed unexpectedly.) - Stack Overflow

.NET has a bug where it expects that the server will include a Connection: close response header if it will close the connection after the response is complete. If the server closes the connection without the Connection: Close header (entirely valid per RFC2616), .NET will encounter the closed connection when attempting to send the next request on the connection and it will throw this exception. What .NET should be doing is silently creating a new connection and resending the request on that new connection.

Thursday, June 12, 2014

Check out this page for more details => ?: Operator (C# Reference)

int input = Convert.ToInt32(Console.ReadLine());

string classify; // if-else construction.

if (input > 0) classify = "positive";

else classify = "negative";

// ?: conditional operator. classify = (input > 0) ? "positive" : "negative";

The condition must evaluate to true or false. If condition is true, first_expression is evaluated and becomes the result. If condition is false, second_expression is evaluated and becomes the result. Only one of the two expressions is evaluated.

Either the type of first_expression and second_expression must be the same, or an implicit conversion must exist from one type to the other.

You can express calculations that might otherwise require an if-else construction more concisely by using the conditional operator. For example, the following code uses first an if statement and then a conditional operator to classify an integer as positive or negative.

Check out this page for more details

?: Operator (C# Reference)

The Html Agility Pack contains a number of classes, all in the HtmlAgilityPack namespace. Therefore, start by adding a using statement (or Imports statement if you are using VB) to the top of your code-behind class:

Using HtmlAgilityPack

To download a web page from a remote server, use the HtmlWeb class's Load method, passing in the URL to download.
[ example ] var webGet = new HtmlWeb();
[ example ] var document = webGet.Load(url);
The Load method returns an HtmlDocument object. In the above code snippet we've assigned this returned object to the local variable document. The HtmlDocument class represents a complete HTML document and contains a DocumentNode property, which returns an HtmlNode object that represents the root node of the document.

The HtmlNode class has several germane properties worth noting. There are properties for traversing the DOM, including:
        - ParentNode
        - ChildNodes
        - NextSibling
        - PreviousSibling

There are properties for determining information about the node itself, such as:
        - Name - gets or sets the node's name. For HTML elements this property returns (or assigns) the name of the tag - "body" for the <body> tag, "p" for a <p> tag, and so on.
        - Attributes - returns the collection of attribu for this element, if any.
        - InnerHtml - gets or sets the HTML content within the node.
        - InnerText - returns the text within the node.
        - NodeType - indicates the type of the node. Can be Document, Element, Comment, or Text.

There are also methods for retrieving particular nodes relative to this one. For instance, the Ancestors method returns a collection of all ancestor nodes. And the SelectNodes method returns a collection of nodes that match a specified XPath expression.

Selecting Meta Tags off an html page
[ example ] var metaTags = document.DocumentNode.SelectNodes("//meta");
If there are no <meta> tags in the document then, at this point, metaTags will be null. But if there are one or more <meta> tags then metaTags will be a collection of matching HtmlNode objects. We can enumerate these matching nodes an display their attributes.

You can click on this link for more information: Parsing HTML Documents with the Html Agility Pack - 4GuysFromRolla.com

Screen scraping is the process of programmatically accessing and processing information from an external website. For example, a price comparison website might screen scrape a variety of online retailers to build a database of products and what various retailers are selling them for. Typically, screen scraping is performed by mimicking the behavior of a browser - namely, by making an HTTP request from code and then parsing and analyzing the returned HTML.

The .NET Framework offers a variety of classes for accessing data from a remote website, namely the WebClient class and the HttpWebRequest class. These classes are useful for making an HTTP request to a remote website and pulling down the markup from a particular URL, but they offer no assistance in parsing the returned HTML. Instead, developers commonly rely on string parsing methods like String.IndexOf, String.Substring, and the like, or through the use of regular expressions.

Another option for parsing HTML documents is to use the Html Agility Pack, a free, open-source library designed to simplify reading from and writing to HTML documents. The Html Agility Pack constructs a Document Object Model (DOM) view of the HTML document being parsed. With a few lines of code, developers can walk through the DOM, moving from a node to its children, or vice versa. Also, the Html Agility Pack can return specific nodes in the DOM through the use of XPath expressions. (The Html Agility Pack also includes a class for downloading an HTML document from a remote website; this means you can both download and parse an external web page using the Html Agility Pack.)

This article shows how to get started using the Html Agility Pack and includes a number of real-world examples that illustrate this library's utility. A complete, working demo is available for download at the end of this article. Read on to learn more!


This is the part that I wanted to lay emphasis onto, as follows:

Linq to Objects approach

public string GetInnerTextWithLinq() {   var document = new HtmlDocument();   document.Load(new FileStream("test.html", FileMode.Open));   var node = document.DocumentNode.Descendants("div").Where(     d => d.Attributes.Contains("class") && d.Attributes["class"].Value.Contains("required")).SingleOrDefault();   return node.InnerText; }
Check the link for more details and feel free to add your comments
Crawling a web sites with HtmlAgilityPack

Know us

Our Team

Tags

Video of the Day

Contact us

Name

Email *

Message *