Wednesday, October 22, 2008

Reset Visual Studio toolbox

When I created a Windows Mobile project, the controls in Toolbox were missing. In place of the usual controls is a tab labelled "#13119". The usual remedy of right-clicking the Toolbox and then selecting Reset Toolbox did not help.

After some searching of Visual Studio folders, I finally found the solution. You need to navigate to the following folder:

C:\Documents and Settings\\Local Settings\Application Data\Microsoft\VisualStudio\9.0

And within this folder are some hidden files. Simply remove the following files:

"toolbox.tbd", "toolboxIndex.tbd", "toolbox_reset.tbd", "toolboxIndex_reset.tbd"

Then restart Visual Studio 2008. Your controls should now come back up! ;-)

Tuesday, October 14, 2008

linkserver Query syntax

SELECT CONVERT(varchar(30), Org_Insert_Date, 103) AS Expr1, Org_Insert_Date
FROM NewBusiness_Listing
WHERE (BList_Id = 10012)




CONVERT(varchar(30),, 103)




frmReports obj = new frmReports();
obj.Owner = this;
this.Visible = false;
obj.Visible = true;


SELECT:

select * from openquery(’my_linked_server’, ’select * from table_schema.table_name’)

INSERT:

insert openquery(’my_linked_server, ’select column_1, column2 from table_schema.table_name’)
values (’my_value1', ‘my_value2')

UPDATE:

update openquery(’my_linked_server, ’select column_1, column_2 from table_schema.table_name where pk = pk_value’)
set column_1 = ‘my_value1', column_2 = ‘my_value2'

DELETE:

delete from openqueryopenquery(’my_linked_server, ’select * from table_schema.table_name where pk = pk_value’)

Saturday, October 11, 2008

Change Back Colour of Mdi form

copy past the code in form load event


MdiClient ctlMDI;

// Loop through all of the form's controls looking
// for the control of type MdiClient.
foreach (Control ctl in this.Controls)
{
try
{
// Attempt to cast the control to type MdiClient.
ctlMDI = (MdiClient) ctl;

// Set the BackColor of the MdiClient control.
ctlMDI.BackColor = this.BackColor;
}
catch (InvalidCastException exc)
{
// Catch and ignore the error if casting failed.
}
}

GetType(),typeof,obj is Form3

foreach(Form frm in mdiParent.MdiChildren) //where mdiParent is the MDI
Container...
{
if(form.GetType() == typeof(FormToClose)) //where FormToClose is Form
you want to close...
form.Close();
}


foreach (Form obj in MdiChildren)
{
if (obj is Form3)
{
obj.WindowState = FormWindowState.Maximized;
}
}

Friday, October 10, 2008

BackgroundWorker

public partial class frmLogin : Form
{
BackgroundWorker initData;
public frmLogin()
{
InitializeComponent();
initData = new BackgroundWorker();
InitializeBackgoundWorker();
}

private void InitializeBackgoundWorker()
{
initData.DoWork += new DoWorkEventHandler(init_DoWork);
initData.RunWorkerAsync();
}


void init_DoWork(object sender, DoWorkEventArgs e)
{
Data.Read_Data();
ReportData.fillData();
}

How to do auto page refresh in ASPX

How to do auto page refresh in ASPX

If you have a requirement something like auto redirect page to login page or auto refresh the current window within 10 sec or auto close window after 10 sec then you can write some lines of code in java script to achieve this


There are multiple ways to auto refresh/auto close browser, some very simple ways are below with examples.


1) Auto page refresh à you can write below code inside tag on top of your ASPX page






Note: Content takes two parameter 1)
2)


2) Auto page redirect à you can write below code inside tag on top of your ASPX page







Note:
http-equiv="Refresh" à This tag will do page auto refresh
content="," à action when page refresh


3) Auto new page open à If you want to open new window after 10 sec then you can create a java script function say "OpenNewWindow" and use this function like below







Note: content="," , 650 =height 1000= width.

function OpenNewWindow(url, h, w)
{
window.open(url,"","width=" + w + ",height=" + h + ",scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes,
directories=no,status=yes,left=5,top=5");
}


4) Auto page close à if you want to close the browser after 10 sec then write below code on top of your ASPX page

//OR


How to Read/Write xml string in different way using C#.net
How to Read/Write xml string in different way using C#.net



Namespace



using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.IO;
using System.Text;

Example Value



string xmlProduct = "
100
"


Read XML




1) First way you can read string xml using dataset



StringReader productDetails = new StringReader(xmlProduct);
DataSet dsProduct = new DataSet();
dsProduct.ReadXml(productDetails);



2) If you have proper XML format value in file




DataSet dsProduct = new DataSet();
dsProduct.ReadXml("C:\Read.xml");



3) You can use XmlTextReader to read xml




string nodeText; int depth;
//In this way you can convert Xmlstring to memoryStream
byte[] data = Encoding.ASCII.GetBytes(xmlProduct);
MemoryStream memStream = new MemoryStream(data);

XmlTextReader textReader = new XmlTextReader(memStream);
XmlNodeType nodeType;



while (textReader.Read())
{
textReader.MoveToFirstAttribute();
nodeType = textReader.NodeType;
if (nodeType.CompareTo(XmlNodeType.Attribute) == 0)
{
nodeText = textReader.Value;
depth = textReader.Depth;
}
}



4) You can use CmlDocument object to read xml,This is the best way to read xml string to read node by node and all attributes.



XmlDocument xmlProductDoc = new XmlDocument();
xmlProductDoc.LoadXml(xmlProduct);




for (int i = 0; i < xmlProductDoc.GetElementsByTagName("product").Count;i++)
{
string xmlVal = xmlProductDoc.GetElementsByTagName("product").innerXml;
string xmlAttributeVal = xmlProductDoc.GetElementsByTagName("product").
Attributes ["value"].value;
}





Write XML

1) You can use XmlTesWriter to write xml file

XmlTextWriter myXmlTextWriter = new XmlTextWriter("books.xml", null);
myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteStartDocument(false);
myXmlTextWriter.WriteDocType("bookstore", null, "books.dtd", null);
myXmlTextWriter.WriteComment("This file represents inventory database");
myXmlTextWriter.WriteStartElement("bookstore");
myXmlTextWriter.WriteStartElement("book", null);
myXmlTextWriter.WriteAttributeString("genre", "autobiography");
myXmlTextWriter.WriteAttributeString("publicationdate", "1990");
myXmlTextWriter.WriteAttributeString("ISBN", "0-4567-123-9");
myXmlTextWriter.WriteElementString("title", null, "Baby book");
myXmlTextWriter.WriteStartElement("Author", null);
myXmlTextWriter.WriteElementString("first-name", "Ritesh");
myXmlTextWriter.WriteElementString("last-name", "Kesharwani");
myXmlTextWriter.WriteEndElement();
myXmlTextWriter.WriteElementString("price", "8.9");
myXmlTextWriter.WriteEndElement();
myXmlTextWriter.WriteEndElement();
//Write the XML to file and close the myXmlTextWriter
myXmlTextWriter.Flush();
myXmlTextWriter.Close();



2) Basic way to write xml into file

http://riteshk.blogspot.com/2005/03/how-to-readwrite-into-xml.html

HTTP Handlers and HTTP Modules in ASP.NET

Good article posted by Mansoor Ahmed Siddiqui in 15Second on HTTP Handlers and HTTP Modules in ASP.NET, see below link

http://www.15seconds.com/issue/020417.htm