Posted by: gazishaheen on: March 16, 2009
Syntax for creating JavaScript libraries
All JavaScript libraries consists of two parts:
For the sake of our discussion, let’s pretend you’ve just created a fabulous code that writes out today’s date:
<script type=”text/javascript”>
function todaydate(){
var today_date= new Date()
var myyear=today_date.getYear()
var mymonth=today_date.getMonth()+1
var mytoday=today_date.getDate()
document.write(myyear+”/”+mymonth+”/”+mytoday)
}
</script>
Using the above code, lets create a library out of it, so multiple pages can all display a nice date without having to physically include the above code on that page.
Step 1: Open up your text editor (such as notepad), type out the above code, and save it as an individual file with the extension .js (ie: displaydate.js). An external library should include the entire script, minus the surrounding script tags.
Step 2: On all pages that use the above library, create a reference to it by using the below code. It consist of a <script> tag with the optional src property included inside:
<script src=”displaydate.js” type=”text/javascript”>
</script>
By including the above reference, your browser will now download the code stored inside displaydate.js, and run it as if the code was physically typed onto the page. The library file does not have to be stored in the same directory as the page using it. In fact, you can even reference a library that’s on a distant domain!
<script src=”http://www.yahoo.com/displaydate.js”>
</script>
While the biggest reason for using JavaScript libraries is obvious (allows you to easily distribute one code for use on many pages), a secondary reason is not. A JavaScript library, when used on multiple pages, is actually more efficient than directly embedding the code inside the library on each page. Once the browser encounters the library the first time around, it saves the containing code in cache. Subsequent requests for the library on other pages will result in the library being loaded from cache, or the speed demon!
Posted by: gazishaheen on: March 16, 2009
How to create a resource. In my case, I want to create an icon. It’s a similar process, no matter what sort of data you want to add as a resource though. 1. Right click the project you want to add a resource to. Do this in the Solution Explorer. Select the “Properties” option from the list. 2. Click the “Resources” tab. 3. The first button along the top of the bar will let you select the type of resource you want to add. It should start on string. We want to add an icon, so click on it and select “Icons” from the list of options. 4. Next, move to the second button, “Add Resource”. You can either add a new resource, or if you already have an icon already made, you can add that too. Follow the prompts for whichever option you choose. 5. At this point, you can double click the newly added resource to edit it. Note, resources also show up in the Solution Explorer, and double clicking there is just as effective How to use a resource. Great, so we have our new resource and we’re itching to have those lovely changing icons… How do we do that? Well, lucky us, C# makes this exceedingly easy. There is a class called Properties.Resources that gives you access too all your resources, so my code ended up being as simple as: paused = !paused; if (paused) notifyIcon.Icon = Properties.Resources.Red; else notifyIcon.Icon = Properties.Resources.Green; From my experience: Use of Resource file in windows application I have only worked with string resources. First use some namespaces using System.Resources; using System.Globalization; Add resource file. Initialize resource manager in form constructor method. m_ResourceManager = new ResourceManager(“[namespace].[resourceFilePath]“, System.Reflection.Assembly.GetExecutingAssembly()); Set Culture value in same method, right after initializing resource manager. Thread.CurrentThread.CurrentUICulture = CultureInfo.CurrentCulture; Read the string resource in the following way- m_ResourceManager.GetString(“[string_key]“) From my experience: Use of Resource file in web application Add Asp folder App_GlobalResources then add resource files in this folder. Read the string resource in the following way- In .aspx page : In (.cs)code behind file: Resources.[ResourceFileName].[key];
Posted by: gazishaheen on: June 7, 2008
function loadTOCNode(){}
var sectionFilter = “type != ‘notice’ && type != ‘securedata’ && type != ‘querywords’”;
var tocArrow = “/library/images/support/kbgraphics/public/en-us/downarrow.gif”;
var depthLimit = 10;
var depth3Limit = 10;
var depth4Limit = 5;
var depth5Limit = 3;
var tocEntryMinimum = 1;
loadTOCNode(1, ‘summary’);
This problem may occur when SQL Server 2005 is not configured to accept remote connections. By default, SQL Server 2005 Express Edition and SQL Server 2005 Developer Edition do not allow remote connections. To configure SQL Server 2005 to allow remote connections, complete all the following steps:
| • | Enable remote connections on the instance of SQL Server that you want to connect to from a remote computer. |
| • | Turn on the SQL Server Browser service. |
| • | Configure the firewall to allow network traffic that is related to SQL Server and to the SQL Server Browser service. |
This article describes how to complete each of these steps.
loadTOCNode(1, ‘moreinformation’);
loadTOCNode(2, ‘moreinformation’); You must enable remote connections for each instance of SQL Server 2005 that you want to connect to from a remote computer. To do this, follow these steps:
| 1. | Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Surface Area Configuration. |
| 2. | On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections. |
| 3. | On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Remote Connections, click Local and remote connections, click the appropriate protocol to enable for your environment, and then click Apply.
Note Click OK when you receive the following message: |
| 4. | On the Surface Area Configuration for Services and Connections page, expand Database Engine, click Service, click Stop, wait until the MSSQLSERVER service stops, and then click Start to restart the MSSQLSERVER service. |
loadTOCNode(2, ‘moreinformation’); If you are running SQL Server 2005 by using an instance name and you are not using a specific TCP/IP port number in your connection string, you must enable the SQL Server Browser service to allow for remote connections. For example, SQL Server 2005 Express is installed with a default instance name of Computer Name\SQLEXPRESS. You are only required to enable the SQL Server Browser service one time, regardless of how many instances of SQL Server 2005 you are running. To enable the SQL Server Browser service, follow these steps.
Important These steps may increase your security risk. These steps may also make your computer or your network more vulnerable to attack by malicious users or by malicious software such as viruses. We recommend the process that this article describes to enable programs to operate as they are designed to, or to implement specific program capabilities. Before you make these changes, we recommend that you evaluate the risks that are associated with implementing this process in your particular environment. If you choose to implement this process, take any appropriate additional steps to help protect your system. We recommend that you use this process only if you really require this process.
| 1. | Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Surface Area Configuration. |
| 2. | On the SQL Server 2005 Surface Area Configuration page, click Surface Area Configuration for Services and Connections. |
| 3. | On the Surface Area Configuration for Services and Connections page, click SQL Server Browser, click Automatic for Startup type, and then click Apply.
Note When you click the Automatic option, the SQL Server Browser service starts automatically every time that you start Microsoft Windows. |
| 4. | Click Start, and then click OK. |
Note When you run the SQL Server Browser service on a computer, the computer displays the instance names and the connection information for each instance of SQL Server that is running on the computer. This risk can be reduced by not enabling the SQL Server Browser service and by connecting to the instance of SQL Server directly through an assigned TCP port. Connecting directly to an instance of SQL Server through a TCP port is beyond the scope of this article. For more information about the SQL Server Browser server and connecting to an instance of SQL Server, see the following topics in SQL Server Books Online:
| • | SQL Server Browser Service |
| • | Connecting to the SQL Server Database Engine |
| • | Client Network Configuration |
loadTOCNode(2, ‘moreinformation’); These steps apply to the version of Windows Firewall that is included in Windows XP Service Pack 2 (SP2) and in Windows Server 2003. If you are using a different firewall system, see your firewall documentation for more information.
If you are running a firewall on the computer that is running SQL Server 2005, external connections to SQL Server 2005 will be blocked unless SQL Server 2005 and the SQL Server Browser service can communicate through the firewall. You must create an exception for each instance of SQL Server 2005 that you want to accept remote connections and an exception for the SQL Server Browser service.
SQL Server 2005 uses an instance ID as part of the path when you install its program files. To create an exception for each instance of SQL Server, you must identify the correct instance ID. To obtain an instance ID, follow these steps:
| 1. | Click Start, point to Programs, point to Microsoft SQL Server 2005, point to Configuration Tools, and then click SQL Server Configuration Manager. |
| 2. | In SQL Server Configuration Manager, click the SQL Server Browser service in the right pane, right-click the instance name in the main window, and then click Properties. |
| 3. | On the SQL Server Browser Properties page, click the Advanced tab, locate the instance ID in the property list, and then click OK. |
To open Windows Firewall, click Start, click Run, type firewall.cpl, and then click OK.
loadTOCNode(3, ‘moreinformation’); To create an exception for SQL Server 2005 in Windows Firewall, follow these steps:
| 1. | In Windows Firewall, click the Exceptions tab, and then click Add Program. |
| 2. | In the Add a Program window, click Browse. |
| 3. | Click the C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe executable program, click Open, and then click OK.
Note The path may be different depending on where SQL Server 2005 is installed. MSSQL.1 is a placeholder for the instance ID that you obtained in step 3 of the previous procedure. |
| 4. | Repeat steps 1 through 3 for each instance of SQL Server 2005 that needs an exception. |
loadTOCNode(3, ‘moreinformation’); To create an exception for the SQL Server Browser service in Windows Firewall, follow these steps:
| 1. | In Windows Firewall, click the Exceptions tab, and then click Add Program. |
| 2. | In the Add a Program window, click Browse. |
| 3. | Click the C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe executable program, click Open, and then click OK.
Note The path may be different depending on where SQL Server 2005 is installed. |
Posted by: gazishaheen on: May 31, 2008
What will I do when I want to search a string in a varchar field, but case have to be ignored?
–>The sample query has given me solution.
select *
from table1
where IGNORE CASE (field1 != field2);
In Case of SQL Server 2005, it compares varchar ignoring case (by default).
Posted by: gazishaheen on: May 5, 2008
SELECT * FROM `student` LIMIT 20, 10
This will return 10 records from 21st record. That is from 21st record to 30th record. Here is the output
Posted by: gazishaheen on: April 7, 2008
You have an XML document that needs to be broken apart into its constituent parts. Each part can then be sent to a different destination (possibly a web service) to be processed individually. This solution is useful when you have a large document, such as a phonebook , an invoice and etc, in XML form.
In order to separate the XML items, we will load an XmlDocument with the invoice XML from the MyDoc.xml file:
<?xml version="1.0" encoding="UTF-8" ?> <MyDoc Date='2005-10-31' Designer='Shahab Fatemi'> <Test> <Date>2005-10-31</Date> <PersianDate>1384-08-09</PersianDate> </Test> <BookList> <Name>C#.NET</Name> <Author>Shahab Fatemi</Author> <Price>49.99$</Price> <Publisher>Naji</Publisher> </BookList> <PhoneBook> <No number='1'> <Name>Shahab</Name> <Family>Fatemi</Family> <Country>IRAN</Country> <City>Esfahan</City> <MobileNumber>0913-319-9328</MobileNumber> <E-Mail>shahab_f_m@yahoo.com</E-Mail> </No> <No number='2'> <Name>Noosha</Name> <Family>xx</Family> <Country>IRAN</Country> <City>Esfahan</City> <MobileNumber>0913-xxx-xxxx</MobileNumber> <E-Mail>noosha@x.com</E-Mail> </No> <No number='3'> <Name>Navid</Name> <Family>Khosravi</Family> <Country>IRAN</Country> <City>Esfahan</City> <MobileNumber>0913-123-4567</MobileNumber> <E-Mail>navid@x.com</E-Mail> </No> <No number='4'> <Name>Mehrdad</Name> <Family>Saifi</Family> <Country>IRAN</Country> <City>Esfahan</City> <MobileNumber>0913-123-4567</MobileNumber> <E-Mail>kechele@kachal.com</E-Mail> </No> </PhoneBook> </MyDoc>
The code to tear this document apart, and send the various information pieces to their respective departments, is shown here:
#region XML XmlDocument xmlDoc = new XmlDocument( ); // pick up MyDoc from deposited directory xmlDoc.Load(@"..\..\MyDoc.xml"); // get the MyDoc element node XmlNode MyDoc = xmlDoc.SelectSingleNode("/MyDoc"); // get the MyDoc date attribute XmlAttribute invDate = (XmlAttribute)MyDoc.Attributes.GetNamedItem("Date"); // get the MyDoc number attribute XmlAttribute invNum = (XmlAttribute)MyDoc.Attributes.GetNamedItem("Designer"); #endregion #region tear apart <Test> // Process the <Test> information to Accounting XmlElement Test = xmlDoc.CreateElement("Test"); // correlate this information back to the original MyDoc number and date Test.Attributes.Append((XmlAttribute)invDate.Clone( )); Test.Attributes.Append((XmlAttribute)invNum.Clone( )); XmlNodeList TestList = xmlDoc.SelectNodes("/MyDoc/Test"); // add the <Test> information to the document foreach(XmlNode TestInfo in TestList) { Test.AppendChild(TestInfo.Clone( )); } Console.WriteLine("Test:\r\n{0}",Test.OuterXml); // Save a copy of the document FileStream fileStream = File.Create(@"..\..\Test.xml"); byte [] bytes = Encoding.ASCII.GetBytes(Test.OuterXml); fileStream.Write(bytes,0,bytes.Length); fileStream.Close( ); #endregion #region tear apart <BookList> // Process the <BookList> information to Accounting XmlElement BookList = xmlDoc.CreateElement("BookList"); // correlate this information back to the original MyDoc number and date BookList.Attributes.Append((XmlAttribute)invDate.Clone( )); BookList.Attributes.Append((XmlAttribute)invNum.Clone( )); XmlNodeList Booklist = xmlDoc.SelectNodes("/MyDoc/BookList"); // add the <BookList> information to the document foreach(XmlNode BookListInfo in Booklist) { BookList.AppendChild(BookListInfo.Clone( )); } Console.WriteLine("BookList:\r\n{0}",BookList.OuterXml); // Save a copy of the document fileStream = File.Create(@"..\..\BookList.xml"); bytes = Encoding.ASCII.GetBytes(BookList.OuterXml); fileStream.Write(bytes,0,bytes.Length); fileStream.Close( ); #endregion #region tear apart <PhoneBook> // Process the item information to <PhoneBook> XmlElement PhoneBook = xmlDoc.CreateElement("PhoneBook"); // correlate this information back to the original MyDoc number and date PhoneBook.Attributes.Append((XmlAttribute)invDate.Clone( )); PhoneBook.Attributes.Append((XmlAttribute)invNum.Clone( )); XmlNodeList itemList = xmlDoc.SelectNodes("/MyDoc/PhoneBook/No"); // add the item information to the document foreach(XmlNode item in itemList) { PhoneBook.AppendChild(item.Clone( )); } Console.WriteLine("PhoneBook:\r\n{0}",PhoneBook.OuterXml); // Save a copy of the document fileStream = File.Create(@"..\..\PhoneBook.xml"); bytes = Encoding.ASCII.GetBytes(PhoneBook.OuterXml); fileStream.Write(bytes,0,bytes.Length); fileStream.Close( ); #endregion
The “MyDoc” containing the various pieces of XML data for the web services are listed in the following sections:
<Test Date="2005-10-31" Designer="Shahab Fatemi"> <Test> <Date>2005-10-31</Date> <PersianDate>1384-08-09</PersianDate> </Test> </Test>
<BookList Date="2005-10-31" Designer="Shahab Fatemi"> <BookList> <Name>C#.NET</Name> <Author>Shahab Fatemi</Author> <Price>49.99$</Price> <Publisher>Naji</Publisher> </BookList> </BookList>
<PhoneBook> <No number='1'> <Name>Shahab</Name> <Family>Fatemi</Family> <Country>IRAN</Country> <City>Esfahan</City> <MobileNumber>0913-319-9328</MobileNumber> <E-Mail>shahab_f_m@yahoo.com</E-Mail> </No> <No number='2'> <Name>Noosha</Name> <Family>xx</Family> <Country>IRAN</Country> <City>Esfahan</City> <MobileNumber>0913-xxx-xxxx</MobileNumber> <E-Mail>noosha@x.com</E-Mail> </No> <No number='3'> <Name>Navid</Name> <Family>Khosravi</Family> <Country>IRAN</Country> <City>Esfahan</City> <MobileNumber>0913-123-4567</MobileNumber> <E-Mail>navid@x.com</E-Mail> </No> <No number='4'> <Name>Mehrdad</Name> <Family>Saifi</Family> <Country>IRAN</Country> <City>Esfahan</City> <MobileNumber>0913-123-4567</MobileNumber> <E-Mail>kechele@kachal.com</E-Mail> </No> </PhoneBook> How to get protected object GetNodeValue(XmlDocument xmlDocumentIn, string sNodeName){ object oRetVal = null; /* Returns the list of nodes whose name is 'sNodeName' */ XmlNodeList oxmlNodeList = xmlDocumentIn.GetElementsByTagName(sNodeName); /*Looping through the xml nodes to get the first one */ foreach (XmlNode oxmlNode in oxmlNodeList){ oRetVal = oxmlNode.InnerXml; break;} return oRetVal;}
Posted by: gazishaheen on: April 6, 2008
The out and the ref parameters are used to return values in the same variables, that you pass an an argument of a method. These both parameters are very useful when your method needs to return more than one values.
In this article, I will explain how do you use these parameters in your C# applications.
The out Parameter
The out parameter can be used to return the values in the same variable passed as a parameter of the method. Any changes made to the parameter will be reflected in the variable.
class mathClass
{
public static int TestOut(out int iVal1, out int iVal2)
{
iVal1 = 10;
iVal2 = 20;
return 0;
}
public static void Main()
{
int i, j; // variable need not be initialized
Console.WriteLine(TestOut(out i, out j));
Console.WriteLine(i);
Console.WriteLine(j);
}
}
The ref parameter
The ref keyword on a method parameter causes a method to refer to the same variable that was passed as an input parameter for the same method. If you do any changes to the variable, they will be reflected in the variable.
You can even use ref for more than one method parameters.
TestRefP
{
using System;
public class myClass
{
public static void RefTest(ref int iVal1 )
{
iVal1 += 2;
}
public static void Main()
{
int i; // variable need to be initialized
i = 3;
RefTest(ref i );
Console.WriteLine(i);
}
}
}
Posted by: gazishaheen on: March 9, 2008
March 9, 2008 Print Screen on Mac OS: Who Needs A Print Screen Key?
One would assume that there is no print screen function in OS X. Well, I got some news and it might be a shocker. OS X has more robust print screen functionality than Windows XP.
Just use any of the following commands to place a shiny new PDF on your desktop.
CMD + Shift + 3
This will take a screenshot of your entire screen.
CMD + Shift + 4
This will bring up a selection tool so you can make a rectangular screenshot of a certain area.
CMD + Shift + 4 + Space Bar
This will turn your cursor into a tiny camera. Use this camera to take a picture of the Dock, a menu, or a window and it will crop the background automatically for the resulting image.
Note: If you hold down the Control key during and of the above commands the image gets copied to your clipboard, ready to paste, rather than creating a PDF on your desktop