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:

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

Functions:

Security

-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.

Versioning:

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

Deployment:

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:

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\MyAssemblies]@=”C:\\MyAssemblies

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.

Advertisements

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 :

http://www.codeguru.com/vb/vb_internet/aspnet/article.php/c15645__1/New-Features-in-Visual-Studio-2010-and-the-NET-Framework-40.htm

http://msdn.microsoft.com/en-us/library/bb383815.aspx

http://msdn.microsoft.com/en-us/library/bb386063.aspx

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

RECONFIGURE

EXEC master.dbo.sp_configure ‘xp_cmdshell’, 1

RECONFIGURE

Step2:

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’

or

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 : http://amitpatriwala.wordpress.com/2010/04/02/save-select-query-result-into-textfile/

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


http://www.oratransplant.nl/2007/10/26/using-iframe-shim-to-partly-cover-a-java-applet/

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 https://viralsarvaiya.wordpress.com/2009/07/08/make-a-pdf-file-from-asp-net/ 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 : https://viralsarvaiya.wordpress.com/2009/07/08/make-a-pdf-file-from-asp-net/

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");

 Response.Cache.SetCacheability(HttpCacheability.NoCache);

 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);

 pdfDoc.Open();

 pdfDoc.NewPage();

 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");

 pdfDoc.Add(jpg);

 pdfDoc.Add(paragraph);

 pdfDoc.Close();

 Response.Write(pdfDoc);

 Response.End();
 }

for more knowledge of itextsharp :
http://somewebguy.wordpress.com/2009/05/08/itextsharp-simplify-your-html-to-pdf-creation/

http://xpode.com/ShowArticle.aspx?ArticleId=134

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

Calculating Work-Days in T-SQL

Posted by Viral Sarvaiya on May 3, 2010


Overview

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 :

http://www.sqlservercentral.com/articles/Advanced+Querying/calculatingworkdays/1660/

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

 
%d bloggers like this: