10 Tips for Writing High-Performance Web Applications

http://msdn.microsoft.com/en-us/magazine/cc163854.aspx

Jquery

http://www.tutorialspoint.com/jquery/index.htm

linq

single record get
===================

http://www.codeproject.com/Answers/182358/Linq-to-xml-output-element-value.aspx#answer1


http://www.dotnetperls.com/convert-milliseconds-seconds-minutes

http://rumandcode.wordpress.com/2008/09/03/multiple-join-fields-in-linq/

http://msdn.microsoft.com/en-us/library/bb397941.aspx


slibinlig
http://msdn.microsoft.com/en-us/library/bb675160.aspx

http://www.java2s.com/Code/XML/XSLT-stylesheet/precedingsiblingandfollowingsibling.htm

IEnumerable status = from obj in xmlDoc.Descendants("AvailFlt")
where (string)obj.Element("AirV") == (string)elementchild.Element("AirV") && (string)obj.Element("FltNum") == (string)elementchild.Element("FltNum")
&& (string)obj.Element("StartAirp") == (string)elementchild.Element("StartPt") && (string)obj.Element("EndAirp") == (string)elementchild.Element("EndPt")
&& (string)obj.Element("StartTm") == (string)elementchild.Element("StartTm") && (string)obj.Element("StartDt") == (string)elementchild.Element("StartDt")
&& (string)obj.Element("EndTm") == (string)elementchild.Element("EndTm")
select obj;






//XElement single;
//if (status.Count() == 0)
//{
// //handle no elements returned
//}
//else if (status.Count() > 1)
//{
// //handle more than 1 elements returned
//}
//else
//{
XElement single = status.Single();
//}

XElement el2 = ((IEnumerable)single
.XPathEvaluate("following-sibling::*[1]"))
.Cast()
.First();

dictionary

http://www.dotnetperls.com/dictionary-lookup


http://www.dotnetperls.com/dictionary-keys

Converting between XDocument and XmlDocument, XElement and XmlElement

http://brianary.blogspot.com/2010/02/converting-between-xdocument-and.html

 public static XmlDocument ToXmlDocument(this XDocument xdoc)
  {
    var xmldoc = new XmlDocument();
    xmldoc.Load(xdoc.CreateReader());
    return xmldoc;
  }
  
  ///
  /// Converts an XmlDocument to an XDocument.
  ///

  /// The XmlDocument to convert.
  /// The equivalent XDocument.
  public static XDocument ToXDocument(this XmlDocument xmldoc)
  {
    return XDocument.Load(xmldoc.CreateNavigator().ReadSubtree());
  }
  
  ///
  /// Converts an XElement to an XmlElement.
  ///

  /// The XElement to convert.
  /// The equivalent XmlElement.
  public static XmlElement ToXmlElement(this XElement xelement)
  {
    return new XmlDocument().ReadNode(xelement.CreateReader()) as XmlElement;
  }
  
  ///
  /// Converts an XmlElement to an XElement.
  ///

  /// The XmlElement to convert.
  /// The equivalent XElement.
  public static XElement ToXElement(this XmlElement xmlelement)
  {
    return XElement.Load(xmlelement.CreateNavigator().ReadSubtree());
  }



public XmlElement doAvail(XmlDocument xmlRequest, XmlDocument xmlFilter)
{

XmlElement xmlResponse = null;
try
{

XmlSelect xws = new XmlSelect();
NetworkCredential credentials = new NetworkCredential("PCC69TX", "Badur69tx");
CredentialCache cc = new CredentialCache();
cc.Add(new Uri(xws.Url), "Basic", credentials);
xws.Credentials = cc;

xws.PreAuthenticate = true;
xmlResponse = xws.SubmitXml("DynGalileoCopy_69TX", xmlRequest.DocumentElement, xmlFilter.DocumentElement);


XElement x = XmlLinqConversionExtensions.ToXElement(xmlResponse);

System.Xml.Linq.XDocument xmlDoc = new System.Xml.Linq.XDocument( x);

var persons = from person in xmlDoc.Descendants("AvailFlt")
select new
{
AirV = person.Element("AirV").Value,
FltNum = person.Element("FltNum").Value,
StartDt = person.Element("StartDt").Value,
StartAirp = person.Element("StartAirp").Value,
EndAirp = person.Element("EndAirp").Value,
NumStops = person.Element("NumStops").Value,
StartTm = person.Element("StartTm").Value,
EndTm = person.Element("EndTm").Value,
JrnyTm = person.Element("JrnyTm").Value,
EndDt = person.Element("EndDt").Value,

};
rptUserList.DataSource = persons;
rptUserList.DataBind();

}
catch (Exception ex)
{
// TextBox2.Text = "Error Message : \n " + ex.Message + "\n\n\n Stack Trace : \n" + ex.StackTrace;
}
return xmlResponse;
}

public XmlDocument BuildRequest()
{

XmlDocument doc = new XmlDocument();
DateTime tomorrow = DateTime.Today.AddDays(90.0);
string req = "\r\n";
req += " \r\n";
req += " \r\n";
req += " 1\r\n";
req += " \r\n";
req += " " + tomorrow.ToString("yyyyMMdd") + "\r\n";
req += " DEN\r\n";
req += " ORD\r\n";
req += " 1200\r\n";
req += " D\r\n";
req += " 0800\r\n";
req += " 1400\r\n";
req += " \r\n";
req += " B\r\n";
req += " B\r\n";
req += " \r\n";
req += "
\r\n";
req += "
\r\n";
req += "
\r\n";
doc.LoadXml(req);
return doc;

}

public XmlDocument BuildFilter()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<_/>");
return doc;
}

linq

http://stackoverflow.com/questions/4526734/how-to-read-xml-file-using-linq-in-c

http://www.techrepublic.com/blog/programming-and-development/access-xml-data-using-linq-to-xml/594


http://weblogs.asp.net/scottgu/archive/2007/08/07/using-linq-to-xml-and-how-to-build-a-custom-rss-feed-reader-with-it.aspx

http://www.dbtutorials.com/retrieve/linq-to-xml-cs.aspx
XDocument xmlDoc = XDocument.Load(Server.MapPath("personkrs.xml"));

var persons = from person in xmlDoc.Descendants("Person")
select new
{
Name = person.Element("Name").Value,
City = person.Element("City").Value,
//Age = person.Element("Age").Value,
};
GridView1.DataSource = persons;
GridView1.DataBind();





Paxton
Munich
29


Mike
Orlando
33


Ella
LA
13


Ingrid
Oslo
63

E-mail Validation Using REGEX

string email = txtEmail.Text.ToString();
string pattern = @"^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|" + @"0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z]" + @"[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$";
System.Text.RegularExpressions.Match match = Regex.Match(email, pattern, RegexOptions.IgnoreCase);
if (match.Success)
{
}
Else
{
{
MessageBox.Show("Don't Leave the Field Empty", "Name Entry Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}

http://royalarun.blogspot.com/2010/09/e-mail-validation-using-regex.html

Option Explicit statement and Option Strict Statement

Option Explicit Statement

The Option Explicit has two modes. On and Off mode.

If Option Explicit mode in ON , you have to declare all the variable before you use it in the program . If not , it will generate a compile-time error whenever a variable that has not been declared is encountered .If the Option Explicit mode is OFF , Vb.Net automatically create a variable whenever it sees a variable without proper declaration.
By default the Option Explicit is On

Option Strict Statement
Visual Basic allows conversions of many data types to other data types. Data loss can occur when the value of one data type is converted to a data type with less precision or smaller capacity. A run-time error occurs if such a narrowing conversion fails. Option Strict ensures compile-time notification of these narrowing conversions so they can be avoided.
On
Optional. Enables Option Strict checking.
Off
Optional. Disables Option Strict checking. If On or Off is not specified, the default is Off.

Commonly used interfaces in .Net

Class Description

IComparable
-----------
Implemented by types whose values can be ordered; for example, the numeric and string classes. IComparable is required for sorting.

IDisposable
-----------
Defines methods for manually disposing of an object. This interface is important for large objects that consume resources, or objects that lock access to resources such as databases.

IConvertible
------------
Enables a class to be converted to a base type such as Boolean,Byte, Double, or String.

ICloneable
----------
Supports copying an object.

IEquatable
----------
Allows you to compare to instances of a class for equality. For example, if you implement this interface, you could say “if (a == b)”.

IFormattable
------------
Enables you to convert the value of an object into a specially formatted string. This provides greater flexibility than the base ToString method.

Generics in .Net Framework

Used to Reduced run-time errors,The compiler cannot detect type errors when you cast
to and from the Object class.the runtime will throw an exception

Using generics allows the compiler to catch this type of bug before your program runs

Generics improves runtime Performance.

Eg:
// Add a double and an int using the Obj class
Obj ob = new Obj(10.125, 2005);
Console.WriteLine((double)ob.t + (int)ob.u);

// Add a double and an int using the Gen class
Gen gb = new Gen(10.125, 2005);
Console.WriteLine(gb.t + gb.u);

If you run that code in a console application, the Obj and Gen classes produce exactly
the same results. However, the code that uses the Gen class actually works faster
because it does not require boxing and unboxing to and from the Object class.

What is the basic difference between Dataset and Typed Dataset ? When would you use Typed dataset?

Typed DataSet is precompiled one

For Example in Normal DataSet this is how we use to get data.

ds.Tables["Employee"].Rows[0][0]

In typed DataSet usage is strongly bound.

ds.EmployeeTable.Rows[0].EmpIdColumn

Here every thing is typed no need to use index/name to identify table or column name.

Typed dataset yields less errors than mornal dataset in all the way.

Typed Dataset is faster than the normal dataset .


Typed DataSet

// C#
// This accesses the CustomerID column in the first row of
// the Customers table.
string s;
s = dsCustomersOrders1.Customers[0].CustomerID;
Untyped Datasets

// C#
string s = (string) dsCustomersOrders1.Tables["Customers"].Rows[0]["CustomerID"];

In addition to being easier to work with, the syntax for the typed dataset provides type checking at compile time, greatly reducing the possibility of errors in assigning values to dataset members

The problem of typed dataset is dynamic behaviour

Difference between Int32.Parse,Convert.Int32

Int32.Parse Method:
-------------------
Converts the string representation of a number to its 32-bit signed integer equivalent.
-When s is a null reference, it will throw ArgumentNullException.
-If s is other than integer value, it will throw FormatException.
-When s represents a number out of range, it will throw OverflowException.

Convert.ToInt32(string):
-------------------------
Converts the specified string representation of 32-bit signed integer equivalent. This calls in turn Int32.Parse () method.
-When s is a null reference, it will return 0 rather than throw ArgumentNullException.
-If s is other than integer value, it will throw FormatException.
-When s represents a number out of range, it will throw OverflowException.

Int32.TryParse Method:
----------------------
Converts the specified string representation of 32-bit signed integer equivalent to out variable, and returns true if it is parsed successfully, false otherwise.
-When s is a null reference, it will return 0.
-If s is other than an integer value, the out variable will have 0.
-When s represents a number out of range, the out variable will have 0


Int32.parse(string)
Int32.Parse (string s)


string s1 = "1234";
string s2 = "1234.65";
string s3 = null;
string s4 = "123456789123456789123456789123456789123456789";

int result;
bool success;

result = Int32.Parse(s1); //-- 1234
result = Int32.Parse(s2); //-- FormatException
result = Int32.Parse(s3); //-- ArgumentNullException
result = Int32.Parse(s4); //-- OverflowException

Convert.ToInt32(string)


For example:
result = Convert.ToInt32(s1); //-- 1234
result = Convert.ToInt32(s2); //-- FormatException
result = Convert.ToInt32(s3); //-- 0
result = Convert.ToInt32(s4); //-- OverflowException


success = Int32.TryParse(s1, out result); //-- success => true; result => 1234
success = Int32.TryParse(s2, out result); //-- success => false; result => 0
success = Int32.TryParse(s3, out result); //-- success => false; result => 0
success = Int32.TryParse(s4, out result); //-- success => false; result => 0

The using keyword has two major uses:

As a directive, when it is used to create an alias for a namespace or to import types defined in other namespaces. See using Directive.

As a statement, when it defines a scope at the end of which an object will be disposed. See using Statement.



Using 'using'

A typical scenario where we could use the using statement is :

Collapse
string connString = "Data Source=localhost;Integrated " +
"Security=SSPI;Initial Catalog=Northwind;";

using (SqlConnection conn = new SqlConnection(connString))
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT ID, Name FROM Customers";

conn.Open();

using (SqlDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
Console.WriteLine("{0}\t{1}", dr.GetString(0), dr.GetString(1));
}
}
Note

The using statement is only useful for objects with a lifetime that does not extend beyond the method in which the objects are constructed. Remember that the objects you instantiate must implement the System.IDisposable interface.

There is no equivalent for the using statement in vb.net. You have to use the try finally block.

Generate a report using Crystal Reports in Visual Studio 2010

http://www.codeproject.com/KB/aspnet/Crstalreportusingvs2010.aspx

Create Resource Files for ASP.NET Web Sites

http://www.codeproject.com/KB/aspnet/GlobalizingLocalizing.aspx

1) create mybasePage class
public class mybasePage:Page
{
public mybasePage()
{
//
// TODO: Add constructor logic here
//
}
static string cultureName;

public static string CultureName
{
get { return cultureName; }
set { cultureName = value; }
}

protected override void InitializeCulture()
{

if (!String.IsNullOrEmpty(cultureName))
{
Thread.CurrentThread.CurrentCulture =
CultureInfo.CreateSpecificCulture(cultureName);

Thread.CurrentThread.CurrentUICulture = new
CultureInfo(cultureName);
}

base.InitializeCulture();
}

}

2. default.aspx source












style="height: 26px" />


Go to Sample Page



code:
protected void Button1_Click(object sender, EventArgs e)
{

CultureName = DropDownList1.SelectedItem.Value.ToString();

}
3)create sample.aspx page: source




Set
Language



4) create resource files
Sample.gu-IN.resx,Sample.mr-IN.resx,Sample.resx

How To configure SQL server to store session state

http://blogs.msdn.com/b/akshayns/archive/2008/10/04/how-to-configure-sql-server-to-store-a-session-state.aspx



http://msdn.microsoft.com/en-us/library/ms178586.aspx

Difference and Similarity between Dispose/Finalizer/Destructor:

1. Dispose called by CLR. Finalizer called by GC

2. Dispose and Finalizers can clean unmanaged resources. After Dispose -> GC will be called, also after Finalizer->GC will be called but this will be the second time, so Finalizer has performace issues.

3. Finalizers if implemented will always be called, unless GC.SupressFinalizer is called from Dispose. Dispose shall be called only if IDispoable interface is implemented

4. If none of Dispose and Finalizer is present then the Destructor is called?

I do not understand this - Dispose or Finalize methods (it depends on which method is called earlier): I guessed it will always be Dispose followed by Finalizer, when will it be other way round.

5. Why cannot destructor free Unmanaged resources? Imagine if we do not have Dispose or Finalizer?

6. Destructor - Last method to be called by GC.



Conclusion - Have Dispose and Destructor both but not the Finalizer? Any specific time when to use Finalizer? Ofcourse when no Dispose is there, but other than that?