Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

Archive for May, 2010

Difference between Assembly and dll

Posted by Viral Sarvaiya on May 29, 2010

Whats the difference between Assembly and dll in .net.? This is the important question in any .net interview.So i thought of summarising the information which i gathered from various sources.


Assembly  contains meta data ,manifest,resource files.

Metadata:Classes,interfaces,base class,scope,properties.

Manifest:Assembly name,version,culture info, strong name,list of all files, type reference and reference assembely



-StrongName: Public/private key decryptyion/encryption correspondingly.

-digital certificate to assembly using signcode.exe :Gives details abt developers identity.

Type Identity:

Defing a type “Datastore” in 2 different assembly..Net framework can differentiate it.

Reference Scope:

-Gives info about its type and resources.

-Gives info abt other assemblies which it depends on.


Each assembly has a 128-bit version number that is presented as a set of four decimal pieces: Major.Minor.Build.Revision


Assemblies are the natural unit of deployment.

Assembly with different version can be present only in GAC folder which has the ability to differentiate diff version.

You cant add a file with 2 diff version in same project.Bcoz bin folder of the project will not have 2 files with same file name.

What’s the difference between private and shared assembly?

Private assembly is used inside an application only and does not have to be identified by a strong name. Shared assembly can be used by multiple applications and has to have a strong name.

Strong Name:

  • A strong name includes the name of the assembly, version number, culture identity, and a public key token.
  • The .NET Code Access Policy can be used to grant or restrict permissions to assemblies based on their strong name. In addition, the strong name can also be used programmatically to control access to resources.
  • It allows assemblies to have the same name, because the assemblies are identified by their unique information—not their name.

Steps in creatting strong name:

1. This scheme relies on a private key that is used for encryption and a public key that decrypts. To create a file containing this key pair, use the Strong Name command-line utility as shown here:

SN –k KeyFileName

SN –k  KeyLib.snk

2. [assembly: AssemblyKeyFile(“KeyLib.snk”)]

3.Add this KeyLib.snk to the project.

4.Gacutil /I gettimelibrary.dll

If this assembly is used in client projects.The public key token of the referenced assembly is stored in the manifest of the client assembly as a way to reference the target assembly.

To make this appear in add reference u need to do 2 things:


1.Create MY Assemblies  folder in above location

2.Give the path of ur dll file in value of a Default key.

Assembly Dll
An assembly  is the unit of deployment and security for managed code projects.  It is a .NET Component and can be used only in .NET managed applications.Compiled code at run time is an assembly and After compilation of the requested ASP.NET file is complete, the assembly is loaded into the application domain, allowing late binding.

Codes in APP_Code folder during compilation will become one assembly.

Assembly  present in bin can have either strong/weak Name and assembly in GAC Should have strong name.

DLL contains library code to be used by any program running on Windows. A DLL may contain either structured or object oriented libraries.

Dll is an assembly.


Posted in ASP.NET | Tagged: , , , , , , , , | Leave a Comment »

New Features in Visual Studio 2010 and the .NET Framework 4.0

Posted by Viral Sarvaiya on May 29, 2010

Visual Studio 2008 may be better than sliced bread, but the development team at Microsoft has already been working on the next release. They have recently given us Visual Studio 2010 and the .NET Framework 4.0 as a Community Technology Preview (CTP); it boasts several features that would appeal to developers.

This article won’t go into every single feature, but will go into features that are the most relevant to .NET developers. Please note that because this is a CTP, it doesn’t mean that the final release will be exactly as you see in the CTP or as is described here. I can go over the features roughly as follows:

New Features in the Visual Studio 2010 IDE and .NET Framework 4.0

  • Call Hierarchy of methods
  • A New Quick Search
  • Multi-targeting more accurate
  • Parallel Programming and Debugging
  • XSLT Profiling and Debugging
  • The XSD Designer

New ASP.NET features

  • Static IDs for ASP.NET Controls
  • The Chart control
  • Web.config transformation

New VB.NET features

  • Auto Implemented Properties for VB.NET
  • Collection Initializers
  • Implicit Line Continuations
  • Statements in Lambda Expressions

New C# features

  • Dynamic Types
  • Optional parameters
  • Named and Optional Arguments

For more details :

Posted in Visual Studio | Tagged: , , , , , , | Leave a Comment »

Save Select query result into Textfile

Posted by Viral Sarvaiya on May 29, 2010

Here I am explaining how to export query results into text file. Please follow below steps to archive this thing.

Step 1:

Enabled the xp_cmdshell

By default disabled in SQL 2005 for security reasons.

To enable it, use the Surface Area Configuration tool or sp_configure

To enable xp_cmdshell using sp_configure, use below query :

EXEC master.dbo.sp_configure ‘show advanced options’, 1


EXEC master.dbo.sp_configure ‘xp_cmdshell’, 1



To save your SELECT query results to a text file, use below query :

EXEC master..xp_cmdshell ‘bcp “select * from adtype.dbo.adbrite” queryout “c:\text.txt” -c -T -x’


EXEC master..xp_cmdshell ‘bcp “select * from Adbrite..Adtype” queryout “c:\text.txt” -U sa -P sa123-c -T -x’

Database Name : Adbrite

Table Name : Adtype

Database User Name : sa

Database Password : password

for more detail :

Posted in Sql Server | Tagged: , , , | Leave a Comment »

Using IFrame Shim to (partly) cover a Java applet

Posted by Viral Sarvaiya on May 27, 2010

Posted in ASP.NET | Tagged: , , , | Leave a Comment »

Background Image in PDF File with ItextSharp in Asp.Net

Posted by Viral Sarvaiya on May 11, 2010

my past post is demonstrate how to develop the pdf file, but when i search in web that have less example for the image in background.

here i demonstrate how to set image in background in pdf file.

step 1 :

follow the link to create the pdf :

stpe 2 :

here i put the whole code for the image in background.

dont forget to download and put the itextsharp.dll file in bin folder.

void makePDF()
 Response.ContentType = "application/pdf";

 Response.AddHeader("content-disposition", "attachment;filename=test.pdf");


 string imageFilePath = Server.MapPath(".") + "/images/test.jpg";

 iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath);

 // Page site and margin left, right, top, bottom is defined
 Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

 //Resize image depend upon your need
 //For give the size to image
 jpg.ScaleToFit(3000, 770);

 //If you want to choose image as background then,

 jpg.Alignment = iTextSharp.text.Image.UNDERLYING;

 //If you want to give absolute/specified fix position to image.
 jpg.SetAbsolutePosition(7, 69);

 PdfWriter.GetInstance(pdfDoc, Response.OutputStream);



 Paragraph paragraph = new Paragraph("this is the testing text for demonstrate the image is in background \n\n\n this is the testing text for demonstrate the image is in background");






for more knowledge of itextsharp :

Posted in ASP.NET | Tagged: , , , , , , , | 14 Comments »

Calculating Work-Days in T-SQL

Posted by Viral Sarvaiya on May 3, 2010


One of the more serious questions in project scheduling, employee planning, and accounting of time is “How many workdays are there?” In other words, given a start date and an end date, how many weekdays (usually a “workday”) are there in the date range including the start date and the end date?

The normal response I get to that question varies but has been limited to “It can’t be done in SQL”, “Ya gotta use a CURSOR”, or “You have to build a table”. This article will take you through all of the logic behind building a nasty fast “Work Day Calculator” function, the crux of which is a single SELECT statement. A fully commented production-worthy UDF is available at the end of this article.

For more details :

Posted in Sql Server | Tagged: , , | Leave a Comment »

%d bloggers like this: