Quick Notes for easy understanding. Chapters are on C#.Net,Linq,OOPS,Design Patterns,UML,Tools for development, Databases and many others. - Sid
Thursday, April 8, 2010
Wednesday, March 31, 2010
Callback Functions
Callback Functions
A callback function is code within a managed application that helps an unmanaged DLL function complete a task. Calls to a callback function pass indirectly from a managed application, through a DLL function, and back to the managed implementation. Some of the many DLL functions called with platform invoke require a callback function in managed code to run properly.
To call most DLL functions from managed code, you create a managed definition of the function and then call it. The process is straightforward.
Using a DLL function that requires a callback function has some additional steps. First, you must determine whether the function requires a callback by looking at the documentation for the function. Next, you have to create the callback function in your managed application. Finally, you call the DLL function, passing a pointer to the callback function as an argument. The following illustration summarizes these steps.
Callback function and implementation

Callback functions are ideal for use in situations in which a task is performed repeatedly. Another common usage is with enumeration functions, such as EnumFontFamilies, EnumPrinters, and EnumWindows in the Win32 API. The EnumWindows function enumerates through all existing windows on your computer, calling the callback function to perform a task on each window. For instructions and an example, see How to: Implement Callback Functions.
See Also
Tasks
How to: Implement Callback Functions
Other Resources
Thursday, March 4, 2010
Net Send
To work around this problem, change the Startup type of the Messenger service to Automatic, and then start the Messenger service.
To do this, follow these steps:
- Open Windows Explorer.
- In the left pane, right-click My Computer, and then click Manage.
- In the Computer Management window, expand Services and Applications in the left pane, and then click Services.
- In the right pane, double-click Messenger.
- In the Messenger Properties (Local Computer) dialog box, click the General tab.
- On the General tab, select Automatic from the Startup type list, and then click Apply.
- Under Service status, click Start, and then click OK.
Copy to a file and save as .bat ext.
@echo off
:A
Cls
echo MESSENGER
set /p n=User:
set /p m=Message:
net send %n% %m%
Pause
Goto A
Tuesday, March 2, 2010
SQL SERVER - Insert Data From One Table to Another Table - INSERT INTO SELECT - SELECT INTO TABLE
SQL SERVER – Insert Data From One Table to Another Table – INSERT INTO SELECT – SELECT INTO TABLE
Following three questions are many time asked on this blog.
How to insert data from one table to another table efficiently?
How to insert data from one table using where condition to anther table?
How can I stop using cursor to move data from one table to another table?
There are two different ways to implement inserting data from one table to another table. I strongly suggest to use either of the method over cursor. Performance of following two methods is far superior over cursor. I prefer to use Method 1 always as I works in all the case.
Method 1 : INSERT INTO SELECT
This method is used when table is already created in the database earlier and data is to be inserted into this table from another table. If columns listed in insert clause and select clause are same, they are are not required to list them. I always list them for readability and scalability purpose.
USE AdventureWorks
GO
----Create TestTable
CREATE TABLE TestTable (FirstName VARCHAR(100), LastName VARCHAR(100))
----INSERT INTO TestTable using SELECT
INSERT INTO TestTable (FirstName, LastName)
SELECT FirstName, LastName
FROM Person.Contact
WHERE EmailPromotion = 2
----Verify that Data in TestTable
SELECT FirstName, LastName
FROM TestTable
----Clean Up Database
DROP TABLE TestTable
GO
Method 2 : SELECT INTO
This method is used when table is not created earlier and needs to be created when data from one table is to be inserted into newly created table from another table. New table is created with same data types as selected columns.
USE AdventureWorks
GO
----Create new table and insert into table using SELECT INSERT
SELECT FirstName, LastName
INTO TestTable
FROM Person.Contact
WHERE EmailPromotion = 2
----Verify that Data in TestTable
SELECT FirstName, LastName
FROM TestTable
----Clean Up Database
DROP TABLE TestTable
GO
Both of the above method works with database temporary tables (global, local). If you want to insert multiple rows using only one insert statement refer article SQL SERVER – Insert Multiple Records Using One Insert Statement – Use of UNION ALL.
Wednesday, February 17, 2010
Get Alias and Base name of Columns
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace GetColumnName
{
class Program
{
static void Main(string[] args)
{
cn.ConnectionString = "server=******;Integrated Security=false;database=******;Connection Lifetime=300;User ID=******;Password=******";
cn.Open();
//Retrieve records from the Employees table into a DataReader.
cmd.Connection = cn;
cmd.CommandText = "SELECT name as empname FROM Employee";
myReader = cmd.ExecuteReader(CommandBehavior.KeyInfo);
//Retrieve column schema into a DataTable.
schemaTable = myReader.GetSchemaTable();
//For each field in the table...
foreach (DataRow myField in schemaTable.Rows){
//For each property of the field...
foreach (DataColumn myProperty in schemaTable.Columns) {
//Display the field name and value.
Console.WriteLine(myProperty.ColumnName + " = " + myField[myProperty].ToString());
}
Console.WriteLine();
//Pause.
Console.ReadLine();
}
//Always close the DataReader and connection.
myReader.Close();
cn.Close();
}
}
}
Thursday, January 21, 2010
IMAP component C# dot net
http://www.codeproject.com/Messages/2504247/Re-Move-a-message-into-a-folder.aspx
The IMAP commands to accomplish it looks something like this:
UID COPY messageUID "new folder"
UID STORE messageUID +FLAGS (\Deleted)
EXPUNGE
Some popular IMAP components are:
- IPWorks! IMAP Component from /n software http://www.nsoftware.com/products/component/imap.aspx
- Rebex Mail for .NET - http://www.rebex.net/mail.net/tutorial-imap.aspx#folders
- Chilkat IMAP .NET - http://www.chilkatsoft.com/imap-dotnet.asp
- EAGetMail POP3 & IMAP4 COMPONENT 2.5 - http://www.emailarchitect.net/eagetmail/
- Lumisoft - http://www.lumisoft.ee/lsWWW/Download/Downloads/Net/ (free)
- xemail-net - http://xemail-net.sourceforge.net (free)
Download 3 rd party component from
http://www.lesnikowski.com/mail/
it will be download as .exe . Click to install to a specific directory . Latter add mail.dll in reference by browsing to installed lib directory .
Document is available here
http://www.lesnikowski.com/mail/documentation/
Friday, September 4, 2009
How can I use AJAX.NET 1.0 - System.Web.Extensions, Version=1.0.61025.0
How can I use AJAX.NET 1.0 - System.Web.Extensions, Version=1.0.61025.0
If you got this message: "Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified."
1. You must copy dll(s) to Bin folder:
AjaxControlToolkit.dll
System.Web.Extensions.dll v1.0.61025.0 or other
System.Web.Extensions.Design.dll v1.0.61025.0
and maybe
AJAXExtensionsToolbox.dll v1.0.61025.0
You may have add those tags and sections to the web.config:
2. Under the <Configuration> tag, add the following <configSections> sections:
Code:
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
3. Under the <system.web> tag, add the following <pages> sections:
Code:
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
3. Under <compilation>, <httpHandlers> and <httpModules> tags:
Code:
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
5. Under <Configuration> tag, add the following <system.web.extensions> and <system.webServer> sections:
Code:
<system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<!-- <jsonSerialization maxJsonLength="500"> -->
<!-- <converters> -->
<!-- <add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/> -->
<!-- </converters> -->
<!-- </jsonSerialization> -->
<!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
<!-- <authenticationService enabled="true" requireSSL = "true|false"/> -->
<!-- Uncomment the lines below to enable the profile service. To allow profile properties to be retrieved -->
<!-- ...and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and -->
<!-- ...writeAccessProperties attributes -->
<!-- <profileService enabled="true" readAccessProperties="propertyname1,propertyname2" writeAccessProperties="propname1,propname2"/> -->
</webServices>
<!-- <scriptResourceHandler enableCompression="true" enableCaching="true" /> -->
</scripting>
</system.web.extensions>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
</system.webServer>
You can read: Add AJAX to an Existing Web Application
6. On IIS7 you must fix web.config with migrate tool or migrate web.confing to Integrated pipeline mode:
6.1 You must migrate the application configuration to work properly in Integrated mode. You can migrate the application configuration with AppCmd:
Code:
> %windir%\system32\inetsrv\Appcmd migrate config "<ApplicationPath>"
6.2 You can migrate manually by moving the custom entries in in the <system.web>/<httpModules> and <system.web>/<httpHandlers> configuration manually to the <system.webServer>/<handlers> and <system.webServer>/<modules> configuration sections, and either removing the <httpHandlers> and <httpModules> configuration OR adding the following to your application’s web.config:
Code:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
6.3 Use Classic mode as a last resort if you cannot apply the specified workaround.
Moving to Classic mode will make your application unable to take advantage of ASP.NET improvements made possible in Integrated mode, leveraging future features from both Microsoft and third parties that may require the Integrated mode.
You can read: Breaking Changes for ASP.NET 2.0 applications running in Integrated mode on IIS 7.0
Code Formater
| Paste Here Your Source Code | ||||||||||||||
| Source Code Formatting Options | ||||||||||||||
|
||||||||||||||
| Copy Formatted Source Code | ||||||||||||||
| Preview Of Formatted Code |