Monday, October 29, 2012

LINQ Sample

There are three parts in any LINQ Query
a. Data Source  - Could be an array collection, Database TAble, Object Collection, Etc...
b. Creating Query - The LINQ Query Creation
c. Executing Query - Query created doesn't get executed immedietly. It gets executed only during enumeraing the result

Sample

class SampleLINQ
{       
    static void Main()
    {

        //  1. Getting Data source.
        int[] intarray = new int[5] { 3, 1, 9, 63, 17};

        // 2. Query creation.
        var intenumQuery =
            from num in intarray
            where (num % 3) == 0
            select num;

        // 3. Query execution.
        foreach (int intvalue in intenumQuery )
        {
            Console.Write("{0,1} ", num);
        }
    }
}

Wednesday, October 24, 2012

Getting HTML from aspx page and save to file

This post gives the sample code to download the html of an aspx and save in to a file


Add reference to System.Net. namespace.

protected void Download_Click(object sender, EventArgs e)
     {
         WebClient mydwdClient = new WebClient();
         string currentUrl = Request.Url.ToString(); // The page which needs to be downloaded
         string webpageinHTML = String.Empty;
         byte[] bytHTML;
        UTF8Encoding utfenc= new UTF8Encoding();       
         bytHTML = mydwdClient.DownloadData(currentUrl );
        webpageinHTML = utfenc.GetString(bytHTML);         
         Response.Write(webpageinHTML );                   
     }
 

Another method which i found in asp.net forum is

protected override void Render(HtmlTextWriter writer)
{
StringBuilder sbOut = new StringBuilder();
StringWriter swOut = new StringWriter(sbOut);
HtmlTextWriter htwOut = new HtmlTextWriter(swOut);
base.Render(htwOut);
string sOut = sbOut.ToString();

// Send sOut as an Email

writer.Write(sOut);
}

Saturday, September 15, 2012

Interview Questions

Here are some of the interview questions:
It is mixture of asp.net, C#, Vb.Net, OOPS, WebServices, WCF, SQL Server, SSRS, SSIS

a. What is the architecture of Ajax in asp.net (How it actually works)
b. How a asp.net page is processed
c. How to debug asp.net application, SQL Query
d. How to find the Stored Procedures property (what command)
e. DBCC - What for it is used
f. How to take and restore SQL Server Backup
g. How to find SQL Server property
h. What are asp.net page members and methods
i. How to deploy a SSRS report
j. What is delegate
k. What is the difference between delegate and Event
l. How to create cookies
m. What is WCF
n. Difference between WCF and Web Services
o. What is inner exception
p. What is IDisposable Interface
q. What is IEnumerable Interface

.......Will Keep Adding

What's New in ASP.NET 4.5 and Visual Studio 2012

· ASP.NET Core Runtime and Framework
· Asynchronously Reading and Writing HTTP Requests and Responses
· Improvements to HttpRequest handling
· Asynchronously flushing a response
· Support for awaitand Task-Based Asynchronous Modules and Handlers
· Asynchronous HTTP modules
· Asynchronous HTTP handlers
· New ASP.NET Request Validation Features
· Deferred ("lazy") request validation
· Support for unvalidated requests
· AntiXSS Library
· Support for WebSockets Protocol
· Bundling and Minification
· Performance Improvements for Web Hosting
· Key Performance Factors
· Requirements for New Performance Features
· Sharing Common Assemblies
· Using multi-Core JIT compilation for faster startup
· Tuning garbage collection to optimize for memory
· Prefetching for web applications
· ASP.NET Web Forms
· Strongly Typed Data Controls
· Model Binding
· Selecting data
· Value providers
· Filtering by values from a control
· HTML Encoded Data-Binding Expressions
· Unobtrusive Validation
· HTML5 Updates
· ASP.NET MVC 4
· ASP.NET Web Pages 2
· Visual Studio 2012 Release Candidate
· Project Sharing Between Visual Studio 2010 and Visual Studio 2012 Release Candidate (Project Compatibility)
· Configuration Changes in ASP.NET 4.5 Website Templates
· Native Support in IIS 7 for ASP.NET Routing
· HTML Editor
· Smart Tasks
· WAI-ARIA support
· New HTML5 snippets
· Extract to user control
· IntelliSense for code nuggets in attributes
· Automatic renaming of matching tag when you rename an opening or closing tag
· Event handler generation
· Smart indent
· Auto-reduce statement completion
· JavaScript Editor
· Code outlining
· Brace matching
· Go to Definition
· ECMAScript5 support
· DOM IntelliSense
· VSDOC signature overloads
· Implicit references
· CSS Editor
· Auto-reduce statement completion
· Hierarchical indentation.
· CSS hacks support
· Vendor specific schemas (-moz-,-webkit)
· Commenting and uncommenting support
· Color picker
· Snippets
· Custom regions
· Page Inspector
· Publishing
· Publish profiles
· ASP.NET precompilation and merge
We will see each feature one by one in details.

Friday, August 17, 2012

Method Hiding and Overriding in c#


Method Hiding
a. We do not required to implement the base class method with 'Virtual' keyword.
b. We need to implement the subclass method with 'new' keyword
c. If we use hiding concept, there is no relationship between the base class method and the sub class method. The subclass method just hides the base class method
d. If we create a subclass object with base class reference, the object doesnt know that there is another implementation exist in the subclass for the method


Method Overriding
a. We do required to implement the base class method with 'Virtual' keyword.
b. We need to implement the subclass method with 'override' keyword
c. If we use overrider concept, it indicates that the subclass is having override relationship with the baseclass
d. If we create a subclass object with base class reference, the object takes the implementation exist in the subclass for the method

Below are sample code
a. Having two classes with one is base class and another one is subclass

b. Creating three object with one is for base class, next one is subclass with base class referenced, last one is subclass

c. See the output

Singleton Class/ Singleton Design Pattern


Singleton Class/ Singleton Design Pattern
a.       A class for which only one instance can be created.
b.      Provides global point of access
c.       It has the private constructor, so instance cannot be created.
d.      A singleton class cannot be inherited single the constructor is private

Sunday, August 12, 2012

Response.Redirect Vs Server.Transfer

Response.Redirect() sends a redirection header to the client, and the client itself requests the new page.
Server.Transfer() only stops rendering the current page and starts rendering another one. The client is none the wiser.
That's why Server.Transfer() cannot be used to redirect to pages served by another server.

Saturday, July 14, 2012

ADO.NET Entity Framework

Entity Framework

What is Entity Framework?
                It is an Object/Relational mapping framework which helps/ enables developers to work with relational data as an domain specific objects.

What it exactly Mean:
 Suppose a developer needs to write a code to create/ edit and delete and customer information, he creates stored procedures in the database, and he writes the code to calls this procedures with relevant parameters.

If he needs to support more than one database, they need to write different code (database specific) to execute these stored procedures.

What if suppose we have option to access different database with single set of code and also no need to worry much about database connectivity and access??....... That’s what entity framework does.

Since the entity framework integrated with LINQ, we (developer) can issue all queries in the code to do the database operation.  With these features we can now concentrate more on writing business logic instead of spending time on relational data.

Since the entity framework built on ado.net provider model, with existing provider being updated additively to support this entity framework, the developer can easily migrate/ upgrade the application built on asp.net to entity framework.

Some of the Capabilities of Entity Framework:

a.       It supports major database servers.

b.      It can handle real-world database schemas and Stored procedures

c.       Its visual studio integrated features provides option to generate models automatically.

d.      It is integrated with asp.net, WCF, WPF and WCF data services

Some of the high level benefits:

a.       Reduces the development time spending on database access

b.      No need to write different database access code for different databases

c.       Database object schema can be changed without doing changes in the code
Architecture of Entity Framework:

Monday, July 9, 2012

Add Custom Code in SSRS

How to Add Custom Code in SSRS

1.       Create a new .rdl file open it
2.       Open the report and In the Design view, right-click the design surface outside the border of the report and click Report Properties.
3.       Click Code.
4.       In Custom code, type the code. Errors in the code produce warnings when the report runs. The following example creates a custom function named AddPrefix. (Code should be written in vb)
Public Function AddPrefix (ByVal s As String) As String 
Return “INV00” + s

End Function

5.       Use the below code to use this function in your report
=Code. AddPrefix(Fields!InvoiceCode.Value)

Sunday, July 8, 2012

SQL Server 2012 Build-In Functions


Function
AVG
Description
Calculates the average of the Values in a Group.
Syntax
AVG (<>)
Optional
ALL  OR DISTINCT keyword can be used before the <> to get Average based on all values or Distinct values
Example
Select AVG(Math_Marks) From StudentMarks Group By Sections


Function
COUNT
Description
Gives no of items in a group
Syntax
COUNT (<>/ *)
Optional
ALL  OR DISTINCT keyword can be used before the <> to get count of all values or Distinct values
Example
Select Count(Student) From StudentMarks Group By Sections