Friday, May 21, 2010

shortcuts for C# coders

Followings are some useful shortcuts for coders:

Copy a single line - CTRL+C [Move the insertion point at the begin or end and press space bar, then press the shortcut key combination]

Cut a single line - CTRL+X [Move the insertion point at the begin or end and press space bar, then press the shortcut key combination]

Comment a line - CTRL+K, CTRL+C [Keep the insertion point any where on line and press ]

UnComment a line - CTRL+K, CTRL+U [Keep the insertion point any where on line and press ]

Put/Remove a break point - F9

Remove all break points as once - CTRL+SHFT+F9


Expand/Collapse a region- CTRL+M, CTRL+M

Intellisense - Ctrl+Space [Press CTRL again make the drop down transparent]

Build Solution - Ctrl+Shft+B

Expand All regions - Ctrl+M+P

Collapse All regions - Ctrl+M+O


New Break Point - Ctrl+B

Switch to Code view - F7

Switch to Html view - SHIFT + F7

Html ParameterInfo - CTRL + SHIFT + SPACEBAR

GoTo window - CTRL + G

CompleteWord - ALT + RIGHT ARROW
CTRL + SPACEBAR

Comment Selection - CTRL + K, CTRL + C

Uncomment Selection - CTRL + K, CTRL + U

Line Cut - CTRL + L

Line Delete - CTRL + SHIFT + L

Make Lowercase - CTRL + U

Make Uppercase - CTRL + SHIFT + U

Tuesday, May 18, 2010

Creating aspnetdb database

go to below location

C:\Windows\Microsoft.NET\Framework\v2.0.50727

find aspnet_regsql.exe and follow the wizard to creat a new database

Saturday, May 15, 2010

Application Hit Counter

If you wanna know ho wmany times your application page hit you could use appllication start event of Global.aspx
Global.aspx file
Application["AppHitCount"] = 0;

lblConfCode.Text = Session["confCode"].ToString();
Application["AppHitCount"] = int.Parse(Application["AppHitCount"].ToString()) + 1;
lblAppHitCounter.Text = Application["AppHitCount"].ToString();
//lable to display the hits

Wednesday, May 12, 2010

Publish a Web site

1.On the Build menu, click Publish Web Site.

2.In the Publish Web Site dialog box, click the ellipsis button (…) to browse to the location to which you want to publish the Web site.

You can write the Web site output to a local or shared folder, to an FTP site, or to a Web site that you access with a URL. You must have Create and Write permissions in the target location.

3.To be able to change the layout (but not the code) of .aspx files after publishing the Web site, select the Allow this precompiled site to be updateable check box.

4.To name strongly named assemblies using a key file or a key container, select the Enable strong naming on precompiled assemblies check box, and then click OK.

Publishing status is displayed in the taskbar. Depending on the connection speed, the size of the site and the types of content files, publishing time can vary. When publishing is completed, the status of Publish succeeded is displayed.

5.Make any configuration changes that are necessary for your site. For more information, see How to: Configure Published Web Site Projects. You might also want to encrypt specific configuration settings. For more information, see Encrypting Configuration Information Using Protected Configuration.

Tuesday, May 11, 2010

Accessing Config File Mail Settings Programmatically

The .NET Framework 2.0 provides APIs for accessing settings in a configuration file. Here's how you access the mail settings of a config file programmatically:

using System.Configuration;
using System.Web.Configuration;
using System.Net.Configuration;

Configuration configurationFile = WebConfigurationManager.OpenWebConfiguration("PathToConfigFile");

MailSettingsSectionGroup mailSettings = configurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup;

if (mailSettings != null)
{
int port = mailSettings.Smtp.Network.Port;
string host = mailSettings.Smtp.Network.Host;
string password = mailSettings.Smtp.Network.Password;
string username = mailSettings.Smtp.Network.UserName;
}
===============================================================

object path = "~/WebRegAdmin";
Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);

ConfigurationSection appSettings = config.GetSection("connectionStrings");
if (bEncrypt)
{
appSettings.SectionInformation.ProtectSection "DataProtectionConfigurationProvider");
}
else
{
appSettings.SectionInformation.UnprotectSection();
}
config.Save();

Monday, May 10, 2010

log4net DLL

log4net is a tool to help the programmer output log statements to a variety of output targets. In case of problems with an application, it is helpful to enable logging so that the problem can be located. With log4net it is possible to enable logging at runtime without modifying the application binary. The log4net package is designed so that log statements can remain in shipped code without incurring a high performance cost. It follows that the speed of logging (or rather not logging) is crucial.

At the same time, log output can be so voluminous that it quickly becomes overwhelming. One of the distinctive features of log4net is the notion of hierarchical loggers. Using these loggers it is possible to selectively control which log statements are output at arbitrary granularity.

log4net is designed with two distinct goals in mind: speed and flexibility

•Support for multiple frameworks
•Output to multiple logging targets
•Hierarchical logging architecture
•XML Configuration
•Dynamic Configuration
•Logging Context
•Proven architecture
•Modular and extensible design
•High performance with flexibility

Friday, May 7, 2010

What is the difference between JavaScript and jQuery?

JavaScript is a language whereas jQuery is a library written using JavaScript.

What is jQuery anyways?

jQuery is a fast, lightweight JavaScript library that is CSS3 compliant and supports many browsers. The jQuery framework is extensible and very nicely handles DOM manipulations, CSS, AJAX, Events and Animations.

Thursday, May 6, 2010

some Important tools

Reflector (http://www.aisto.com/roeder/dotnet/) - If you only get one tool, this is the one to choose. Decompile any .NET code. I can't even count the number of times I've been able to figure out why I'm getting some random exception back from a system function with this tool. It also faster to use than the .NET documentation, so I use it to lookup API's. Do I need to call Dispose and then Close, or does Dispose call Close, now I know.


Rhino mocks (http://ayende.com/projects/rhino-mocks.aspx) - I can't imagine unit testing without rhino.


Snoop (http://www.blois.us/Snoop/) - Do you develop WPF apps. This visual tree tool will help you figure out how to restyle almost anything.
Wireshark (http://www.wireshark.org/) - Nothing beats this network sniffer
TFS Sidekick (http://attrice.info/cm/tfs/) - All those things you wish TFS did, sidekick does.
Stylus Studio (http://www.stylusstudio.com/) - hands down the best XML tool on the planet.
The Regulator (http://tools.osherove.com/CoolTools/Regulator/tabid/185/Default.aspx) I love regular expressions, but they can a nightmare to debug. This tool makes it regex trial and error fast and easy.
Ghost Doc (http://www.roland-weigelt.de/ghostdoc/) - I like writing code, I don't like writing comments. I like ghost doc.
Sandcastle (http://blogs.msdn.com/sandcastle/) - Again, I like writing code, I don't like writing docs. Make professional looking documentation from your code.
Process Monitor (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) What the heck is locking that file? ProcMon knows.

Binding to Data Using a Data Source Control

In previous versions of ASP.NET, data-bound controls such as the DataList and the DataGrid were bound to data using the DataSource property, which required writing code to retrieve, sort, filter, page, and modify data. While this method is still fully supported, data controls in version 2.0 have the added benefit of binding to a data source control using the DataSourceID property instead.
Data source controls greatly expand the capabilities of data-bound controls introduced in version 2.0, such as the GridView, FormView, and DetailsView controls. When used with data source controls, these controls enable users to easily perform database operations from different data sources, with little or no code.

1) add a data source control, such as a SqlDataSource control
2) add a data-bound control, such as a GridView control and bind it to the data source control

The data source control connects to a data source such as a database or middle-tier object and then retrieves or updates data. The data-bound control can then use this data.

GridView Control

The GridView Web server control is a full-featured data-bound control that displays data in tabular format, and provides the ability to sort, select, edit, and delete records from its associated data source

The GridView control displays one row for each record in the data source, and by default, generates a column for each field. You can, however, choose which fields in the data source will render in the grid.

The GridView control can automatically page over the data, if the underlying data source supports paging.

The GridView control must be bound to a data source; otherwise, the control will not render on the page.

Data binding
Data binding using the DataSourceID property, which allows binding the GridView control to a data source control.

Data binding using the DataSource property, which allows binding to any data source that implements the ICollection or IEnumerable interface, including ADO.NET datasets and datareaders

Saturday, May 1, 2010

IDisposable Interface

Defines a method to release allocated resources

The primary use of this interface is to release unmanaged resources. The garbage collector automatically releases the memory allocated to a managed object when that object is no longer used. However, it is not possible to predict when garbage collection will occur. Furthermore, the garbage collector has no knowledge of unmanaged resources such as window handles, or open files and streams.

Use the Dispose method of this interface to explicitly release unmanaged resources in conjunction with the garbage collector. The consumer of an object can call this method when the object is no longer needed.

e.g
[ComVisibleAttribute(true)]
public interface IDisposable