22.6.10

Web Parts

WebParts give us the option of dragging and dropping of objects on a page as well as, changing titles and border style properties of objects at runtime. Before the introduction of WebParts it was used to be a hectic task because we had to write a lot of JavaScript and had to save the state of objects in a database.

There are two basic things in WebParts:

* WebPart manager

* WebPart zones



* WebPart manager

The WebPartManager is the manager for all webparts. If you use webparts in your web projects you are required to use the WebPartManager. Usually you just drag and drop this into your webform and are ready to go.

* WebPart zones

There are four kinds of zones in webpart zones:

ü WebPart Zone

ü Editor Zone

ü Catalog Zone

ü Connection Zone


Reference: http://dotnetslackers.com/articles/aspnet/UsingWebPartsInASPNet20.aspx

Difference between Debug & Release Build Mode

Debug Mode:
* In debug mode, many of the compiler optimizations are turned off which allow the generated executable match up with the code. This allows breakpoints to be set accurately and allows a programmer to step through the code one line at a time. Debugging information is also generated help the debugger figure out where it is in the source code.
* Debug compile generates .pdb files containing debugging information.
* When an application is built using Debug build, a .pdb file is generated in the bin folder while this does not happen in Release build.
* There will be a speed difference, because of disabling debug methods.
* In release mode, most of the compiler's optimizations are turned on. Chunks of your code could be completely deleted, removed, or rewritten. The resulting executable will most likely not match up with your written code. However, normally release mode will run faster than debug mode due to the optimizations.

Release Mode:
* Production release should be strictly release mode only. This is because debug compilation considerably increases memory footprint since debug symbols are required to be loaded. Additionally it will hit the performance because that will include the optional debug and trace statements in the output IL code.
* The compiler emits an instance of the System.Diagnostics.DebuggableAttribute. In the debug version, the IsJitOptimizerEnabled property is True, in the release version it is False. You can see this attribute in the assembly manifest with ildasm.exe.
* The JIT compiler uses this attribute to disable optimizations that would make debugging difficult. The ones that move code around like loop-invariant hoisting. In selected cases, this can make a big difference in performance. Not usually though.
* Mapping breakpoints to execution addresses is the job of the debugger. It uses the .pdb file and info generated by the JIT compiler that provides the IL instruction to code address mapping. If you would write your own debugger, you'd use ICorDebugCode::GetILToNativeMapping().
* The Debug mode does not optimize the binary it produces (as optimizations can greatly complicate debugging), and generates additional data to aid debugging.
* The Release mode enables optimizations and generates less (or no) extra debug data.

You can append the following code to the AssemblyInfo.cs file:

#if DEBUG

[assembly: AssemblyDescription("Debug")]

#else

[assembly: AssemblyDescription("Release")]

#endif

After compiled to Assembly file (.dll or .exe), right-click the file and check its version property: Comments item is Dubug or Release.

10.6.10

Features in SQL 2005

Features in SQL 2005
===============
*Integrated common language runtime (CLR) support. Stored procedures and functions can be written using your favorite programming language.
*Native XML support.
*XCopy support for moving databases from one location to another.
Robust and reliable installation using either graphical user interface (GUI) or silent modes.
Automated servicing and patching.
*Deep integration with Visual Studio to provide access to rich data controls like the DataGridView, DataNavigator, and DataConnector.
Support for databases up to 4GB.
Support for disconnected systems with SQL Server Service Broker and Replication.
SQL Server Express Manager, a new, easy-to-use database management and query analysis tool.
Easier deployment via Visual Studio ClickOnce (available in Beta 3).

Validation Controls

* Validation Controls
- CompareValidator
We need to compare user input to another value (e.g., another property or constant) in a style similar to the old and ever lasting if statement.
- CustomValidator
Your validation needs does not fit on any of the categories specified in this table but you are still able to write code that checks for the validity of this input.
Here you can use the ValidateEmptyText property to do validation even if the validation value is empty. This is a new feature in ASP.NET 2.0
- RangeValidator
You need to be sure whether the input falls between two bound (Example: User age must be between 18 and 99)
- RegularExpressionValidator
You need the input to follow a consistent pattern (Example: a phone number that must start with '+' and must be composed of 9 to 10 digits)
- RequiredFieldValidator
You need to force the user to input a value inside a particular control and not to leave it empty. (Example: The User Name field in a login form)

General Tips

* Uninstall software’s Without Using Add / Remove Programs:

Approach using Installer

Run->type installer ->
· RClick the msi.

· select properties.

· Go to summary.

· check the title of msi / software name which you want to uninstall.

· RClick the appropriate msi / software and select UnInstall.

25.2.10

Different Types of Paths



There are two options

* Absolute Paths
Link uses the full URL of an object or page. While you can use it within your own site, there is rarely ever a need to do so.

* Relative Paths
Any time you need to send a visitor to another page within your site or include an object from your site (like an image) on one of your pages a relative link will work just fine.

- Document Relative
It is the most widely used type of relative linking, and for good reason. They can easily move up and down your site's hierarchy, in and out of directories (folders) without a hitch.
eg:OPEN img src="images/title.gif" CLOSE
See the above image instead of the products page being in the same directory as the home page it is actually located in a subdirectory. You still need to include the images in the page but the page is in a directory (folder) deeper than the root level of your site.
As you can see you need to move up and out of the products directory in order to get to the images folder in order to access the needed images
eg:OPEN img src="../images/title.gif" CLOSE

- Root Relative
A site root-relative path describes the location of the destination file by describing the route the browser must take from the Web site's root folder (top level in the folder structure).
eg:OPEN img src="/html/images/image1.gif" CLOSE
"/" denotes root directory
You just need to use the System.Web.VirtualPathUtility.ToAbsolute("~") method to convert the ~ to the ApplicationPath.So, if your file is located at "~/common/images/spacer.gif" and you need to specify this path in a client tag like OPEN img CLOSE, ASP.NET would not allow you to use this path unless you use a Server Control like OPEN asp:Image CLOSE.
To continue using the client tag you can use:
OPEN img src="OPEN %=System.Web.VirtualPathUtility.ToAbsolute("~")%CLOSE /common/images/spacer.gif" / CLOSE
and this would be resolved to "/MyApplication/common/images/spacer.gif" where the first forward slash (/) stands for the WebSite root. Thus, the tilde "~" is effectively resolved to "/MyApplication"
Alternatively, Control.ResolveClientUrl can be used. For example
OPEN img src='<%= ResolveClientUrl("~/common/images/spacer.gif")%>' / CLOSE

8.1.10

Server.Transfer Vs Response.Redirect

* Response.Redirect
-It involves a roundtrip to the server.
-you cannot directly access the values, controls and properties of the previous page.
-Suppose you are currently on the Page1.aspx and now you are transferring the user to the Page2.aspx using Response.Redirect then When the Page2 page is requested, Page1 has been flushed from the server’s memory and no information can be retrieved about it unless the developer explicitly saved the information using some technique like session, cookie, application, cache etc
-Response.Redirect can be used for both .aspx and html pages
-Response.Redirect can be used to redirect a user to an external websites.
* Server.Transfer
-It conserves/Preserves server resources by avoiding the roundtrip.
-you can directly access the values, controls and properties of the previous page which you can’t do with Response.Redirect.
-variables can stay in scope and Page2 can read properties directly from Page1 because it’s still in memory, as you know the Server.Transfer just changes the focus from page1 to page2 So in this case browser doesn’t know that any change is happen there that’s why with this method you can access the information about the previous page.
-Server.Transfer can be used only for .aspx pages and is specific to ASP and ASP.NET.
-Server.Transfer can be used only on sites running on the same server. You cannot use Server.Transfer to redirect the user to a page running on a different server.
- you can put values into the Context.Items dictionary for using these values in next page.
eg.
Context.Items["Message"] = "Your password was changed successfully";
Server.Transfer("default.aspx");

18.11.09

Webssite Vs. Web Application

* Fundamentally the behavior of the application types is same but website project type is folder based and WebApp is project type like normal project types in VS studio.In WebApplication project type project file defines the structure of the project.

* WebSite project type contains the folders and anything that you put in the folder are dynamically compiled and be part in the website. More about ASP.NET Website Dynamic compilation here.

* WebApplication project type contains the designer for the ASPX page and you can find the bin folder which contains the compiled assembly.

ASP.NET website project type is dynamic and WebApp is more like structured.

* When you add a class file to the website project it will prompt you that it will place the file in App_code folder under root.
Notice In website project type namespace won't add to the class by default however you can define the namespaces explicitly where as in WebApp it creates the namespace for the class file when you added it to the project.

* WebApp project type is restricted to one language where as Website you can add different language files to the App_Code folder which compiles the files dynamically.

* Referring a user control in WebApp is straight forward.You can define the properties and can be accessed in class files like any other objects where as in website it is not.

* We can put multiple language files in the Website but those files needs to be in same folder. If you change the location of the file then you need to mention in the Web.Config file as follows..
OpnAngl codeSubDirectories ClosAngl
OpnAngl add directory Name="Testfolder"/ClosAngl
OpnAngl /codeSubDirectories ClosAngl
In compilation process you will have the finer degree of control in WebApp and it is not in Website because everything is dynamically compiled.

* When you deploy the WebApps you can just copy the Compiled Assembly and Visual elements to the IIS folder where as in Website you need to copy everything to the IIS to work.

* If you use WebApplication project you can not access Profie at design time
Web site
No solution or project files are required and the pages and source can reside locally (file system, IIS) or remotely (FTP, WebDev/FrontPage extensions) via the File > Open > Web Site… menu option.

Code-behind and classes are typically stored on the web server which compiles them in-memory on demand. Changes can be made to the files without restarting the application and losing sessions.

Web Appli
Like the name implies these are primarily for web applications, those times when you have written a product or solution that happens to have a web interface.

Web application projects exist on your local drive and are treated like any other VS project type and can be added to existing solutions are subject to full compilation, validation and build steps.

Deployment is typically via MSI installers however you can also utilise the addition Web Deployment Projects add-in which allows you to deployment directly to servers which is useful for deploying to test environments.

29.10.09

Project-vs-Product

Product:
Product is, a company that develop and releases Hardware, Middleware, Operating system, Languages, Tools etc are becomes the product. They develop the products for global clients i.e. there are no specific clients for them. Here the requirements are gathered from market and analyze that with some experts and start to develop the product. After developing the products they try to market it as a solution. Here the end users are more than one. Product development is never ending process and customization is possible.

Project:
Project is finding solution to a particular problem to a particular client. It depends on the product. By using the products like Hardware, Middleware, Operating system, Languages and Tools only we will develop a project. Here the requirements are gathered from the client and analyze with that client and start to develop the project. Here the end user is one.

Project--Placing the order before manufacturing process
Product--Placing the order after manufacturing process

PRODUCTS
1 Here the requirements are gathered from market survey.
2 Develop the application for Global clients
3 Products are depends on products
4 End users are more than one
5 Never ending process
PROJECTS
1 Here the requirements are gathered from particular client
2 Develop the application for particular client
3 Projects are depends on products
4 End user is one
5 Once developed it will be finished

23.10.09

SQL Profiler

SQL Profiler captures SQL Server events from a server. The events are saved in a trace file that can be used to analyze and diagnose problem.

The different purposes of using SQL Profiler are:
*It is used to find the cause of the problem by stepping through problem queries.
*It is very useful to analyze the cause of slow running queries.
*It can be used to tune workload of the SQL server.
*It also stores security-related actions that can be reviewed by a security administrator.
*SQL Profiler also supports auditing the actions performed on instances of SQL Server.
*Saved traces can be used by the SQL Server Index Tuning.
*It is also possible to sort and filter the information captured.

*How can you use the SQL Profiler to ensure database security?
*SQL Profiler can audit events like Security, User Activity and DBA Activity.
*Security events include granting, revoking or denying permissions of a user or role.
*End user activity like logins and logouts can be audited.Enabling of roles for an application can also be done.

When do you use SQL Profiler?
*When some queries are performing slowly
*To trace and monitor events of the SQL server
*When indexes need to be fine tuned
*When security is a concern, it can be used to audit and review security activities
*It can be used when troubleshooting to find root cause of an issue

What are the tasks performed by SQL Profiler?
*The SQL Profiler can save traces to a file or a table. These saved traces can be used by the SQL Server Index Tuning.
*To be able to execute a set of actions in the future, the traces can be saved to an SQL script.
*The SQL Profiler can directly replay the traces.
*It is also possible to sort and filter the information captured. This helps in finding performance bottlenecks or deadlocks in the application.

How can you use the SQL Profiler to ensure database security?
SQL Profiler can audit events like Security, User Activity and DBA Activity.
Security events include granting, revoking or denying permissions of a user or role.
End user activity like logins and logouts can be audited.Enabling of roles for an application can also be done.

How can you reduce the amount of data collected by a trace?
There are various options that you need to fill up before creating a new trace. It is always a better practice to use the default options unless you dont want to get into the details of the data provided by the trace.

There are a lot of events that you can audit. If you need to focus on a particular problem, then you can select the events needed and go through to determine the problem.

8.9.09

What is patindex and charindex in SQL

Patindex: Returns the string position of the first occurrence of pattern
Ex: Select patindex(‘%o%’, ‘Microsoft’)
Note: % is must
Charindex: Same as patindex but you can specify the string position.
Ex: charindex ( Expression1, Expression2 [ , start_location])

What is MSIL, IL

When compiling to managed code, the compiler translates your source code into Microsoft intermediate language (MSIL), which is a CPU-independent set of instructions that can be efficiently converted to native code. MSIL includes instructions for loading, storing, initializing, and calling methods on objects, as well as instructions for arithmetic and logical operations, control flow, direct memory access, exception handling, and other operations. Microsoft intermediate language (MSIL) is a language used as the output of a number of compilers and as the input to a just-in-time (JIT) compiler. The common language runtime includes a JIT compiler for converting MSIL to native code.

Can I write IL programs directly

.assembly MyAssembly {}
.class MyApp {
.method static void Main() {
.entrypoint
ldstr "Hello, IL!"
call void System.Console::WriteLine(class System.Object)
ret
}
}
Just put this into a file called hello.il, and then run ilasm hello.il. An exe assembly will be generated.

What is Portable Executable (PE)

The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR.

What is serialization in .NET?

Serialization is the process of converting an object into a stream of bytes. Deserialization is the opposite process of creating an object from a stream of bytes. Serialization/Deserialization is mostly used to transport objects (e.g. during remoting), or to persist objects (e.g. to a file or database).Serialization can be defined as the process of storing the state of an object to a storage medium. During this process, the public and private fields of the object and the name of the class, including the assembly containing the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created.

• Binary serialization preserves type fidelity, which is useful for preserving the state of an object between different invocations of an application. For example, you can share an object between different applications by serializing it to the clipboard. You can serialize an object to a stream, disk, memory, over the network, and so forth. Remoting uses serialization to pass objects "by value" from one computer or application domain to another.

• XML serialization serializes only public properties and fields and does not preserve type fidelity. This is useful when you want to provide or consume data without restricting the application that uses the data. Because XML is an open standard, it is an attractive choice for sharing data across the Web. SOAP is an open standard, which makes it an attractive choice.
There are two separate mechanisms provided by the .NET class library - XmlSerializer and SoapFormatter/BinaryFormatter. Microsoft uses XmlSerializer for Web Services, and uses SoapFormatter/BinaryFormatter for remoting. Both are available for use in your own code.

6.9.09

Difference Between Product & Project in software

Project or Application:
* One client point of view if we are designing any software it is called project.
* This is custom made for a specific company in a specific domain, by taking the companies requirements.
ex: subiksha

Product :
* Global client point of view if we are designing any software it is called product.
ex: Ms-word.
* Many companies can use it irrespective of domain -
ex: Microsoft Office.

4.9.09

"Debugging" and "Tracing"

Tracing in .NET

So how has tracing been implemented in .NET? In .NET we have objects called Trace Listeners. A listener is an object that receives the trace output and outputs it somewhere; that somewhere could be a window in your development environment, a file on your hard drive, a Windows Event log, a SQL Server or Oracle database, or any other customized data store.

You can think of a Trace Listener as a conduit for passing tracing information from your application to the output store. We write tracing information on Trace Listeners and Trace Listeners in turn output the tracing information to the target media.

Storing tracing information in a data store of some sort provides the flexibility of analyzing the data later on and helps us find the error and performance related patterns in our applications.

The System.Diagnostics namespace provides the interfaces, classes, enumerations and structures that are used for tracing, debugging, and other application and system diagnostic services.

The System.Diagnostics namespace provides two classes named Trace and Debug that are used for writing errors and application execution information in logs. These classes are helpful during the development (to output debug messages, etc) and after deployment (to output performance related patterns, etc). These two classes are the same, except that the methods of the Trace class become part of the release build code whereas methods of the Debug class don't become part of the release build executable.

When you create a new project, define the DEBUG symbol to enable output with the Debug class and the TRACE symbol to enable output with the Trace class. If you create a project in Visual Studio .NET, its Debug version will have these symbols defined.



The System.Diagnostics namespace provides some Trace Listeners. The default Trace Listener is System.Diagnostics.DefaultTraceListener. Write and WriteLine methods of this class route the tracing information to the OutputDebugString and to the Log method of the attached debugger.

.NET framework also introduced the concept of Trace Switches. As the name implies, these are simply switches whose values can be controlled from outside of the application. What I meant by outside of the application is that once an application is compiled and converted to .exe or .DLL files, we don't have to change our code in order to change the values of these switches; we can just update the corresponding entries in .config files and the corresponding switches in our applications will have the updated values. To be more precise,

Trace Switches are simple objects that can be controlled externally through the .config files.

We will learn more about Trace Listeners and Trace Switches as we progress through the article. Following is a simple example of WriteLine method of the Trace and Debug classes.


Trace.WriteLine ("Hello 15Seconds Reader - Trace!") ;
Debug.WriteLine ("Hello 15Seconds Reader - Debug!") ;

When used in debug mode, both of these methods direct the tracing and debugging output to the output windows of the debugger; as shown in the following figure



NEED TO GET MORE ON "http://www.15seconds.com/Issue/020910.htm"

1.9.09

How to use Configuration file in DOTNET

app.config for Windows applications
Windows applications in VS.NET use the name app.config by default for the configuration file. This will not be automatically created when you create a Windows application. If you need a configuration file for your application, open your project in VS.NET, go to the 'Solution Explorer' and right click on the project name. Choose Add > Add new item from the menu and select 'Application Configuration file' from the list of choices. This will create an app.config file for you in the application root.

* To store values in the configuration file, you can create XML elements in the format:
?xml version="1.0" encoding= "utf-8" ?
configuration

appSettings
add key="DatabasePath" value="c:\\projects\data\spider.mdb"
add key="SupportEmail" value="webmaster-1@dotnetspider.com"
appSettings

configuration

* And to read from this config file, just use the following code in your application:

string dbPath =
System.Configuration.ConfigurationSettings.AppSettings["DatabasePath"];
string email =
System.Configuration.ConfigurationSettings.AppSettings["SupportEmail"];

ConfigurationSettings is the class used to access the contents of the configuration file. Since this class is part of the namespace System.Configuration, we have to use the fully qualified name System.Configuration.ConfigurationSettings. As a shortcut, you can use the using directive on top of the file like below:

using System.Configuration;

If you have the above directive on top of the file, then you can directly use the class ConfigurationSettings.

string dbPath = ConfigurationSettings.AppSettings["DatabasePath"];
string email = ConfigurationSettings.AppSettings["SupportEmail"];

In VB.NET, you have to use "( ... )" instead of the "[ ... ]"

Note: When you compile your application, VS.NET will automatically create a file called .exe.config in your bin\debug folder. The contents of the app.config will be automatically copied to this new config file when you compile the application. When you deliver the application to the end user, you have to deliver the exe and this new config file called .exe.config and NOT the app.config. Users can modify the data in .exe.config file and application will read the data from the config file, when restarted.

web.config for Windows applications

The web applications use the same concept, but they use a config file with the name web.config. There are couple of things to note in this case.

web.config is created automatically by VS.NET when you create any web project.
When you compile the web application, web.config is NOT renamed or copied to the BIN folder.
web.config has several default entries in it to support web/IIS configuration & security.
You can add the section in the web.config and add your key/value pairs in that section.
You can have separate web.config files for each directory in your web application, in addition to the one in the root. For each web page, by default, system will look for a web.config in the same folder as the page and if not found, then looks in the parent folder.

28.8.09

Combining C# and VB.Net projects in VS2005

Q: Can a C# project be combined with a VB.Net project in VS 2005?

A: You can compile each project separately then combine them together into a single assembly file using the assembly linker (AL.exe). This is a Microsoft utility that installs in the .Net framework folder (C:\Windows\Microsoft.NET\Framework\v1.1.4322).

Another option is to compile one project into a DLL or EXE then reference it from the other project.

10.7.09

Diff Between Web.config & Machine.Config

* What is Web.Config File?

Web.config file, as it sounds like is a configuration file for the Asp .net web application. An Asp .net application has one web.config file which keeps the configurations required for the corresponding application. Web.config file is written in XML with specific tags having specific meanings.

* What is Machine.config File?

As web.config file is used to configure one asp .net web application, same way Machine.config file is used to configure the application according to a particular machine. That is, configuration done in machine.config file is affected on any application that runs on a particular machine. Usually, this file is not altered and only web.config is used which configuring applications.

* What can be stored in Web.config file?

There are number of important settings that can be stored in the configuration file. Here are some of the most frequently used configurations, stored conveniently inside Web.config file..

1. Database connections
2. Session States
3. Error Handling
4. Security