only My site

Wednesday, July 30, 2008

c# String functions Part1

// Create a Unicode String with 5 Greek Alpha characters
String szGreekAlpha = new String('\u0319',5);
// Create a Unicode String with a Greek Omega character
String szGreekOmega = new String(new char [] {'\u03A9','\u03A9','\u03A9'},2,1);

String szGreekLetters = String.Concat(szGreekOmega, szGreekAlpha, szGreekOmega.Clone());

// Examine the result
Console.WriteLine(szGreekLetters);

// The first index of Alpha
int ialpha = szGreekLetters.IndexOf('\u0319');
// The last index of Omega
int iomega = szGreekLetters.LastIndexOf('\u03A9');

Console.WriteLine("The Greek letter Alpha first appears at index " + ialpha +
" and Omega last appears at index " + iomega + " in this String.");

Window - open, move

Window.open method opnes a window and window.move method Moves the screen position of the upper-left corner of the window to the specified iX and iY position.


mywindow=window.open('BalaSanHome.aspx','whatever','toolbar=no,status=no,width=500,height=250,scrollbars=no,directories=no,location=no,resizable=no,menubar=no,screenX=400,screenY=300,top=290,left=600' ,true);
mywindow.moveTo(300,300);

Correlated Sub query - Sample

SELECT Id, Status_Date,Status_Description FROM T1612_INV_STATUS [ST]
WHERE Status_Date = ( SELECT Max(Status_Date) FROM T1612_INV_STATUS WHERE [ST].Id = Track_Id)

Master Page - Tips

When using masterPage system, i can't access the "ScriptManager1" object within the codebehind of ContentPage file..
You access the scriptManager from a content page using the static GetCurrent method:

ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);

Also we can use Type casting..

if (((MasterPage)Master).FindControl("ScriptManager1") != null)
{
ScriptManager scm;
scm = (ScriptManager)((MasterPage)Master).FindControl("ScriptManager1");
scm.SetFocus(txtHdrDet_CMNumber);
}

Tuesday, July 29, 2008

Los Angeles earthquake

I felt the shake and we came out from the office.

The USGS says a magnitude-5.4 earthquake has struck the L.A, area. Stay with CNN.com Live for continuing coverage.


A moderate, magnitude 5.4 earthquake struck just east of Los Angeles, the U.S. Geological Survey says. The epicenter was about 2 miles southwest of Chino Hills. No injuries or serious damge were reported. But residents were warned to check homes for gas leaks and to be on alert for more aftershocks. "Everything was moving," said iReporter Danny Casler.

Monday, July 28, 2008

Build Events

The screen shot illustrates the post build event( copy dll assembly to d:\ass..path)...You can play around with the events in VS 2005,2008.

TabIndex Property

Browser URL is the first one will get the focus by Default. It can be changed by settong the Focus to a control in the ASP.Net webform. Eg txtInvNo.focus(); Also set the TabIndex property to move the cursor in a customized order.

focus() function won't work in MS AJAX update panel....

Narayana Murthy's words of wisdom

Way back in 1981, Nagavara Ramarao Narayana Murthy and six other young engineering graduates launched an information technology company from a garage in Mumbai.

Murthy had borrowed Rs 10,000 from his wife (Sudha) to launch Infosys Technologies. Infy, as it is popularly known, recently, reported a net profit of Rs 1,302 crore (Rs 13.02 billion) for the quarter ended June 2008.

For 21 years Murthy served as the company's chief executive officer, before he handed over the reins to co-founder Nandan M Nilekani in March 2002.

His life's philosophy and his Success Mantra, read on...

"We were huddled together in a small room in Bombay (now Mumbai) in the hope of creating a brighter future for ourselves, for the Indian society, and perhaps, we dreamed, even for the world."

"Our value system was like the British Constitution - it was all unwritten but extremely well practiced...Our value system is the true strength of Infosys."

"Unless we can sell well we cannot do anything, such as create jobs, pay good salaries and satisfy investors. Right from the beginning we realised that we have to focus on selling better and better in the marketplace."

"Truth is God. Our success at Infosys depends on our continual learning."

"Entrepreneurship is about running a marathon, not a 100 metre dash."

Thursday, July 24, 2008

Wednesday, July 23, 2008

InsertAfter


using System;
using System.IO;
using System.Xml;

public class Sample {

public static void Main() {

XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +

"<title>Pride And Prejudice</title>" +

"</book>");

XmlNode root = doc.DocumentElement;

//Create a new node.
XmlElement elem = doc.CreateElement("price");
elem.InnerText="19.95";

//Add the node to the document.
root.InsertAfter(elem, root.FirstChild);

Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);

}
}

XMLAttributionCollection, Item


public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' publicationdate='1997'> " +

" <title>Pride And Prejudice</title>" +

"</book>");

XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;

Console.WriteLine("Display all the attributes for this book...");
for (int i=0; i < attrColl.Count; i++)
{
Console.WriteLine("{0} = {1}", attrColl.Item(i).Name, attrColl.Item(i).Value);
}

}
}

HTTP, BaseURL(Uniform Resource Indicator)


using System;
using System.IO;
using System.Xml;

public class Sample
{
public static void Main()
{
//Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.Load("http://localhost/baseuri.xml");

//Display information on the attribute node. The value
//returned for BaseURI is 'http://localhost/baseuri.xml'.
XmlAttribute attr = doc.DocumentElement.Attributes[0];
Console.WriteLine("Name of the attribute: {0}", attr.Name);
Console.WriteLine("Base URI of the attribute: {0}", attr.BaseURI);
Console.WriteLine("The value of the attribute: {0}", attr.InnerText);

}
}

Attributes collection


using System;
using System.IO;
using System.Xml;

public class Sample
{
public static void Main(){

XmlDocument doc = new XmlDocument();
doc.LoadXml("" +
"" +
"
");

//Create an attribute collection.
XmlAttributeCollection attrColl = doc.DocumentElement.Attributes;

Console.WriteLine("Display information on each of the attributes... \r\n");
foreach (XmlAttribute attr in attrColl){
Console.Write("{0}:{1} = {2}", attr.Prefix, attr.LocalName, attr.Value);
Console.WriteLine("\t namespaceURI=" + attr.NamespaceURI);
}
}
}

XmlTextWriter & MemoryStream


private byte[] GenerateXXXXXML()
{
byte[] distBytes = new byte[1];

using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
XmlTextWriter xtw = new XmlTextWriter(ms, Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
xtw.WriteProcessingInstruction("xml", "version='1.0' encoding='utf-8'");
xtw.WriteStartElement("PRODValidation");
xtw.WriteAttributeString("xmlns", "http://www.XXX.com/PRODUCT/validate");

// charge type
xtw.WriteStartElement("Query");
xtw.WriteAttributeString("name", "TABLENAME");
xtw.WriteStartElement("Parameters");
xtw.WriteStartElement("Param");
xtw.WriteAttributeString("name", "");
xtw.WriteAttributeString("value", "");
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.WriteStartElement("Result");
xtw.WriteStartElement("Status");
xtw.WriteEndElement();
xtw.WriteStartElement("AdditionalInfo");
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.WriteEndElement();

xtw.WriteEndElement();
xtw.Flush();
ms.Flush();
distBytes = ms.ToArray();
xtw.Close();
}

return distBytes;
}

DataRow Null check

DataRow Null checking before cast to the corresponding datatype.

alertRules.Condition = dr.IsNull("Condition") ? "" : dr["Condition"].ToString();

Copy File from remote location (HTTP, https, FTP..)


string RemoteFolder = @"http://yoursite.com/YourWebFolder/";
string RemoteFile = "yourfile.txt";
string url = RemoteFolder + RemoteFile;
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
StreamReader sr = new
StreamReader(webResponse.GetResponseStream(),Encod ing.ASCII);
string filecontent = sr.ReadToEnd();
StreamWriter sw = new StreamWriter("c:\mynewfile.txt");
sw.Write(filecontent);
sw.Flush();
sw.Close();
sr.Close();

Tuesday, July 22, 2008

XML DOM - Samples

<?xml version='1.0'?>

<bookstore xmlns="urn:newbooks-schema">

<book genre="novel" style="hardcover">

<title>The Handmaid's Tale</title>

<author>

<first-name>Margaret</first-name>

<last-name>Atwood</last-name>

</author>

<price>19.95</price>

</book>

<book genre="novel" style="other">

<title>The Poisonwood Bible</title>

<author>

<first-name>Barbara</first-name>

<last-name>Kingsolver</last-name>

</author>

<price>11.99</price>

</book>

</bookstore>





using System;
using System.IO;
using System.Xml;

public class Sample
{
public static void Main()
{

XmlDocument doc = new XmlDocument();
doc.Load("newbooks.xml");

// Create an XmlNamespaceManager to resolve the default namespace.
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("bk", "urn:newbooks-schema");

// Select and display all book titles.
XmlNodeList nodeList;
XmlElement root = doc.DocumentElement;
nodeList = root.SelectNodes("/bk:bookstore/bk:book/bk:title", nsmgr);
foreach (XmlNode title in nodeList) {
Console.WriteLine(title.InnerXml);
}

}

}


CreateElement:
==============

using System;
using System.IO;
using System.Xml;

public class Sample
{
public static void Main()
{
//Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +

"<title>Pride And Prejudice</title>" +

"</book>");

//Create a new node and add it to the document.
//The text node is the content of the price element.
XmlElement elem = doc.CreateElement("price");
XmlText text = doc.CreateTextNode("19.95");
doc.DocumentElement.AppendChild(elem);
doc.DocumentElement.LastChild.AppendChild(text);

Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);

}
}


using System;
using System.IO;
using System.Xml;

public class Sample
{
public static void Main()
{
//Create the XmlDocument.
XmlDocument doc = new XmlDocument();

//Create a document type node and
//add it to the document.
XmlDocumentType doctype;
doctype = doc.CreateDocumentType("book", null, null, "");
doc.AppendChild(doctype);

//Create the root element and
//add it to the document.
doc.AppendChild(doc.CreateElement("book"));

Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);
}
}

StringDictionary - Collection

StringDictionary is the member of System.Collections.Specialized class

Example:


using System;
using System.Collections;
using System.Collections.Specialized;

public class SamplesStringDictionary {

public static void Main() {

// Creates and initializes a new StringDictionary.
StringDictionary myCol = new StringDictionary();
myCol.Add( "red", "rojo" );
myCol.Add( "green", "verde" );
myCol.Add( "blue", "azul" );

// Display the contents of the collection using foreach. This is the preferred method.
Console.WriteLine( "Displays the elements using foreach:" );
PrintKeysAndValues1( myCol );

// Display the contents of the collection using the enumerator.
Console.WriteLine( "Displays the elements using the IEnumerator:" );
PrintKeysAndValues2( myCol );

// Display the contents of the collection using the Keys, Values, Count, and Item properties.
Console.WriteLine( "Displays the elements using the Keys, Values, Count, and Item properties:" );
PrintKeysAndValues3( myCol );

// Copies the StringDictionary to an array with DictionaryEntry elements.
DictionaryEntry[] myArr = new DictionaryEntry[myCol.Count];
myCol.CopyTo( myArr, 0 );

// Displays the values in the array.
Console.WriteLine( "Displays the elements in the array:" );
Console.WriteLine( " KEY VALUE" );
for ( int i = 0; i < myArr.Length; i++ )
Console.WriteLine( " {0,-10} {1}", myArr[i].Key, myArr[i].Value );
Console.WriteLine();
// Searches for a value.
if ( myCol.ContainsValue( "amarillo" ) )
Console.WriteLine( "The collection contains the value \"amarillo\"." );
else
Console.WriteLine( "The collection does not contain the value \"amarillo\"." ); Console.WriteLine();

// Searches for a key and deletes it.
if ( myCol.ContainsKey( "green" ) )
myCol.Remove( "green" );
Console.WriteLine( "The collection contains the following elements after removing \"green\":" ); PrintKeysAndValues1( myCol );

// Clears the entire collection.
myCol.Clear();
Console.WriteLine( "The collection contains the following elements after it is cleared:" ); PrintKeysAndValues1( myCol );
}

// Uses the foreach statement which hides the complexity of the enumerator.
// NOTE: The foreach statement is the preferred way of enumerating the contents of a collection.


public static void PrintKeysAndValues1( StringDictionary myCol )
{
Console.WriteLine( " KEY VALUE" );
foreach ( DictionaryEntry de in myCol )
Console.WriteLine( " {0,-25} {1}", de.Key, de.Value ); Console.WriteLine(); }

// Uses the enumerator.
// NOTE: The foreach statement is the preferred way of enumerating the contents of a collection.

public static void PrintKeysAndValues2( StringDictionary myCol )
{
IEnumerator myEnumerator = myCol.GetEnumerator();
DictionaryEntry de;
Console.WriteLine( " KEY VALUE" );
while ( myEnumerator.MoveNext() )
{
de = (DictionaryEntry) myEnumerator.Current;
Console.WriteLine( " {0,-25} {1}", de.Key, de.Value );
}
Console.WriteLine();
}
// Uses the Keys, Values, Count, and Item properties.
public static void PrintKeysAndValues3( StringDictionary myCol )
{
String[] myKeys = new String[myCol.Count];
myCol.Keys.CopyTo( myKeys, 0 );
Console.WriteLine( " INDEX KEY VALUE" );
for ( int i = 0; i < myCol.Count; i++ )
Console.WriteLine( " {0,-5} {1,-25} {2}", i, myKeys[i], myCol[myKeys[i]] );
Console.WriteLine();
}
}

Contains() XPath Function in MS DOM

<?xml version="1.0"?>

<!-- This file represents a fragment of a bookstore inventory database -->

<bookstore specialty="novel">

<book>

<Title>Beginning XML</Title>

<Publisher>Wrox</Publisher>

</book>

<book>

<Title>Professional XML</Title>

<Publisher>Wrox</Publisher>

</book>

<book>

<Title>Programming ADO</Title>

<author>

<first-name>Mary</first-name>

<last-name>Bob</last-name>

</author>

<datePublished>1/1/2000</datePublished>

<Publisher>Microsoft Press</Publisher>

</book>

</bookstore>



Add References, by selecting the Microsoft XML 3.0 check box.

Dim doc As MSXML2.DOMDocument
Dim nlist As MSXML2.IXMLDOMNodeList
Dim node As MSXML2.IXMLDOMNode

Set doc = New MSXML2.DOMDocument
doc.setProperty "SelectionLanguage", "XPath"
doc.Load "c:\books.xml"
Set nlist = doc.selectNodes("//book/Title[contains(.,'ADO')]")
MsgBox "Matching Nodes : " & nlist.length

For Each node In nlist
Debug.Print node.nodeName & " : " & node.Text
Next

Source : http://support.microsoft.com/kb/304265

Friday, July 18, 2008

House Model in America

InfranView - Effects



Effects of InfranView s/w - Rock and Zoom Blur..Its cool and fun..

Thursday, July 17, 2008

Entcomm office




Shirdi Sai Baba temple - Los Angeles


InfranView - Image tool


InfranView is a great freeware program that you can download at http://www.irfanview.com and have a really fun time playing with and distorting your own images, as well as using it for normal, everyday editing.

UFrame = Iframe + UpdatPanel

UFrame combines the goodness of UpdatePanel and IFRAME in a cross browser and cross platform solution. It allows a DIV to behave like an IFRAME loading content from any page either static or dynamic. It can load pages having both inline and external Javascript and CSS, just like an IFRAME. But unlike IFRAME, it loads the content within the main document and you can put any number of UFrame on your page without slowing down the browser. It supports ASP.NET postback nicely and you can have DataGrid or any other complex ASP.NET control within a UFrame. UFrame works perfectly with ASP.NET MVC making it an replacement for UpdatePanel. Best of all, UFrame is implemented 100% in Javascript making it a cross platform solution. As a result, you can use UFrame on ASP.NET, PHP, JSP or any other platform.
UFrame does not use IFRAME nor UpdatePanel and thus it is very fast.

<div class="UFrame" id="UFrame1" src="SomePage.aspx?ID=UFrame1" >
<p>This should get replaced with content from Somepage.aspx</p>
</div>

Response from SomePage.aspx is rendered directly inside the UFrame. Here you see two UFrame's are used to load the same SomePage.aspx as if they are loaded inside IFRAME. Another UFrame is used to load AnotherPage.aspx that shows photos from Flickr.

ASP.Net - DoPostBack

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DoPostback.aspx.cs" Inherits="DoPostback" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Untitled Page</title>

<script language="javascript" type="text/javascript">

function enablePostBack()

{

alert("Hi");

//TextBox1 is the first argument(name of control) second argument is "TextChanged" (Serverside event name)

__doPostBack("TextBox1","TextChanged");

}

</script>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:TextBox ID="TextBox1" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

</div>

</form>

</body>

</html>


Server side Code

using System;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

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

if ( !IsPostBack )
{
TextBox1.Attributes.Add("onblur", "Javascript:enablePostBack();");
}
}

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
TextBox2.Text = (Int16.Parse(TextBox1.Text) * 45).ToString();
}
}

Wednesday, July 16, 2008

Display HTML without Execute

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Example</title>

<script language="JavaScript" type="text/javascript">

<!--

function showTags()

{

str=document.getElementById("txtCode").value;

str=str.replace(/[&]/g,'&amp;');

str=str.replace(/[<]/g,'&lt;');

str=str.replace(/[>]/g,'&gt;');

str=str.replace(/[\n]/g,'<br>');



//document.getElementById('show').innerHTML=str;

document.getElementById('txtCodeop').value = str;

}

//-->

</script>

</head>

<body onload="showTags()">

<div id="show"></div>

<TextArea id="txtCode" name="txtCode"></textArea>

<input type=button id=btnSubmit name=btnSubmit onclick="Javascript:showTags();">

<TextArea id="txtCodeop" name="txtCodeop"></textArea>

</body>

</html>

Monday, July 7, 2008

Sort Dropdown List

Hi...

There is no option in Dropdown server control to Sort the list items as like Array sort method. So a small workaround need to do this. Here is a simple sample.

ddlModelType.DataValueField = "key";
ddlModelType.DataTextField = "value";
ddlModelType.DataSource = strDict;
ddlModelType.DataBind();
SortDropDown(ddlModelType);
ddlModelType.Items.Insert(0, new ListItem("Select", "-1"));

private void SortDropDown(DropDownList dd)
{
ListItem[] ar = new ListItem[dd.Items.Count];
long i = 0;
foreach (ListItem li in dd.Items)
{
// ERROR: Not supported in C#: ReDimStatement
ar[i] = li;
i += 1;
}
ListItem[] ar1 = ar;
Array.Sort(ar1, new ListItemComparer());
dd.Items.Clear();
dd.Items.AddRange(ar1);
//dd.Items.AddRange(ListItem ar1);
}

class ListItemComparer : IComparer
{
int System.Collections.IComparer.Compare(object x, object y)
{
ListItem a = (ListItem)x;
ListItem b = (ListItem)y;
CaseInsensitiveComparer c = new CaseInsensitiveComparer();
return c.Compare(a.Text, b.Text);
}
}

VS 2008 Shortcuts & Code snippets

Build
======

Ctrl + Shift + B - Build Solution
Ctrl + Attach to Process

Debugging
===========
F9 - Break point / Toggle Breakpoint
Ctrl + Shift + F9 - Clear All Breakpoints
Ctrl + B + T - Book mark
Ctrl + B + E - Enable Bookmark
Ctrl + B + C - Clear all Bookmarks
Ctrl + B + P - Previous Bookmark
Ctrl + B + N - Next Bookmark

F2 / Crtl + R + R - Rename function with preview

Edit
=====
Cycle Clip Board ring
Ctrl + Shift + V

Ctrl + F - Quick find (Current Document)
Ctrl + Shift + F - Find in files (Entire solution)
Ctrl + Shift + H - Find & Replace
Alt + F12 - Find Symbol
F8 and SHIFT + F8 - Forward and backwards in your search results

Ctrl+E,D - Format Document
Ctrl+E,F - Format Selection or Current cursor line
Ctrl+Shift+U - Make Uppercase
Ctrl+U - Make Lowercase

Comment Selection (Ctrl+E,C)
28. Uncomment Selection (Ctrl+E,U)
Delete Horizontal White Space (Ctrl+E, \)
24. View White Space (Ctrl+E,S)
25. Word Wrap (Ctrl+E,W)
26. Incremental Search (Ctrl+I)


Crtl + Up Arror - Scroll line Down
Crtl + Down Arror - Scroll line Up

Code Snippets
=============

Ctrl + K, Ctrl + X

Create XML file and sinppet to add snippet using Ctrl + k , ctrl _ x.

Add your code in CDATA Tag and save the XML files as "FileName.snippet" Format.

Use Snippet Manager (Ctrl + k, Ctrl + B) to Import the snippet.

Create own Code snippets inside VS
http://msdn.microsoft.com/en-us/library/bb245788.aspx