Monday, April 29, 2013

.NET 4.0 FAQ Part 1 -- The DLR

Simple 7 steps to run your first Azure Blob Program


Step 1:- Ensure you have things at place

Step 2:- What will we do?

Step 3:- Create a web role

Step 4:- Set the blob connection string

Step 5:- Create the blob on webrole onstart

Step 6:- Code your ASP.NET UI

Step 7:- Run the project and enjoy


In this section we will create our first program using Azure blobs. This article creates a simple web page where we upload image files which are stored in azure blobs. We have also created a simple search text box which will help us to search the image blobs with the image file name.
In case you are a complete newbie to azure you can download my two azure basic videos which explain what azure is all about Video1 Video2.

Please feel free to download my free 500 question and answer eBook which covers
.NET , ASP.NET , SQL Server , WCF , WPF , WWF@ .

Step 1:- Ensure you have
things at place

In case you are a complete fresher to Azure,
please ensure you have all the pre-requisite at place. You can read the below
article to get the basic prerequisite

Step 2:-
What will we do?

Azure Blobs help to store large items like
files, in other words its file storage system. In this article we will create a
simple program to upload image files in Azure blob system.

Step 3:-
Create a web role

The first step is to a create a web role
project. In case you are fresher in Azure, you can go through
to understand
how to create a web role project.

So let’s create a simple project with name ‘BlobStorage’. Once you have created
the project it creates two projects one is the cloud service project and the
other is the web role project. Cloud service project has all the necessary
configuration needed for your cloud service project while the web role project
is your project.

Step 4:- Set the blob
connection string

Now the next step is to define a blob
connection string in the service configuration file. So expand the ‘BlobStorage’
project, right click on roles and select properties.

Once you select properties, go to settings tab and add the blob connection
string as shown in the below figure. In the below figure we have added blob
connection string name as ‘BlobConnectionString’.

Click on the right hand eclipse and select ‘Use
development storage’. All the changes done using the setting UI will be
reflected in the ‘ServiceConfiguration’ file as shown above.

Step 5:- Create the blob
on webrole onstart

Now it’s time to start coding. Open the web
role project and open ‘WebRole.cs’ file.

Now let’s write a code on the ‘onstart’ event
to create the blob container.

public override bool OnStart()



Use the ‘CloudStorageAccount’ static class to
set the configuration environment.

public override bool OnStart()


// Set the configuration file


CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>









The next step is to get a reference of the
cloudstorageaccount object using the blob connection string which was provided
when you setup your web role project.

// get the blob connection string

CloudStorageAccount objStorage = CloudStorageAccount.FromConfigurationSetting("BlobConnectionString");

Once we have access to the storage account
object, use the blob end point to create the blob client.

// get the client reference

CloudBlobClient objClient = new CloudBlobClient(objStorage.BlobEndpoint, objStorage.Credentials);

Give a nice name to the container and create
the container object using the client object which you have just created using
the blob end point. Call the ‘CreateIfnotExist’ method of the container to
ensure that you create the blob container only if it does not exist to avoid any

// Get the reference to container

CloudBlobContainer objContainer = objClient.GetContainerReference("mycontainer");

// Create the container if it does not exist


6:- Code your ASP.NET UI

The final step is to create the ASPX page which
will help us upload image files in the blob container which we just created in
the ‘WebRole.cs’ file. You can see in t he below figure we have create a browse
button which help us upload image files and a search text box which will help us
search blob files.

So create the below defined ASPX UI.

In the above ASPX CS UI first get the reference
to the below specified name spaces.

using Microsoft.WindowsAzure;

using Microsoft.WindowsAzure.StorageClient;

In the file upload button we need to insert the
below code snippet to upload the file. So get access to the container object
‘MyContainer’ and call the ‘GetBlobReference’ function to get access to the
cloud blob object.

// Get the storage account reference

CloudStorageAccount objStorage = CloudStorageAccount.FromConfigurationSetting("BlobConnectionString");

// get the Client reference using storage blobend point

CloudBlobClient objClient = new CloudBlobClient(objStorage.BlobEndpoint, objStorage.Credentials);

// Get Container reference

CloudBlobContainer objContainer = objClient.GetContainerReference("mycontainer");

// Get blob reference

CloudBlob obj =objContainer.GetBlobReference(FileUpload1.FileName.ToString());

Set the meta data of the cloud object and open
a blob stream object to write the file. Do not forget to close the blob steam
object once you are done.

// Set meta values

obj.Metadata["MetaName"] = "meta";

// Open a stream using the cloud object

BlobStream blobstream = obj.OpenWrite();

// Write the stream to the blob database

blobstream.Write(FileUpload1.FileBytes, 0, FileUpload1.FileBytes.Count());


Once we upload the file, we will browse through
the blob list to get the list of blobs present in the container.

// Browse through blob list from the container

IEnumerable<IListBlobItem> objBlobList = objContainer.ListBlobs();

foreach (IListBlobItem objItem in objBlobList)


Response.Write(objItem.Uri + "<br>"); 


In the same UI we have provided a search object
to search a blob. To search a blob first get access to the container object and
call the ‘GetBlobReference’ function with the blob name to get reference to the
cloud object.

// Get the blob reference using the blob name provided in the search

CloudBlob obj = objContainer.GetBlobReference(txtSearch.Text);

BlobStream blobstream = obj.OpenRead();

Read the blob stream using the blob steam
object and finally attach this stream with the Image object to display the same
in the HTTP response.

// Create the image object and display the same on the browser response

System.Drawing.Image objimg=null;

objimg = System.Drawing.Image.FromStream(blobstream,true);


Response.ContentType = "image/gif";


Step 7:- Run the project and enjoy

Finally enjoy your first blob program. You can
see in the below figure we have uploaded some image files in the blob.

We can also search the blob using the search
blob text box and you should be able to get the below image display from the
blob database.

34 important ASP.NET Interview questions

34 important ASP.NET Interview questions

Below are 34 important ASP.NET interview questions which repeat again and
again in .NET Interviews .

  1. What is an application object?
  2. what is the difference between Cache object and application object?
  3. How can get access to cache object?
  4. What are dependencies in cache and types of dependencies?
  5. Can you show a simple code showing file dependency in cache?
  6. What is Cache Callback in Cache?
  7. What is scavenging?
  8. What are different types of caching using cache object of ASP.NET?
  9. How can you cache different version of same page using ASP.NET cache object?

  10. How will implement Page Fragment Caching?

  11. Can you compare ASP.NET sessions with classic ASP?

  12. Which are the various modes of storing ASP.NET session?

  13. Is Session_End event supported in all session modes? 106

  14. What are the steps to configure StateServer Mode?

  15. What are the steps to configure SQLServer mode?

  16. Where do you specify session state mode in ASP.NET?

  17. What are the other ways you can maintain state?

  18. What are benefits and Limitation of using Hidden fields?

  19. What is ViewState?

  20. Does the performance for viewstate vary according to User controls?

  21. What are benefits and Limitation of using Viewstate for state management?

  22. How can you use Hidden frames to cache client data ?

  23. What are benefits and limitations of using Hidden frames?

  24. What are benefits and limitations of using Cookies? 109

  25. What is Query String and What are benefits and limitations of using Query

  26. What is Absolute and Sliding expiration?

  27. What is cross page posting?

  28. How do we access viewstate value of this page in the next page ?

  29. Can we post and access view state in another application?

  30. What is SQL Cache Dependency in ASP.NET 2.0?

  31. How do we enable SQL Cache Dependency in ASP.NET 2.0?

  32. What is Post Cache substitution?

  33. Why do we need methods to be static for Post Cache substitution?

  34. Can you explain page life cycle ?

Saturday, April 27, 2013

ASP.NET Interview Questions: - Show Post Cache substitution?

This is one of the asked ASP.Net Interview Questions during the Interview by the Interviewer.

Post cache substitution is used when we want to cache the whole page but also need some dynamic region inside that cached page. Some examples like QuoteoftheDay, RandomPhotos, and AdRotator etc. are examples where we can implement Post Cache Substitution.

Post-cache substitution can be achieved by two means:

  • Call the new Response.WriteSubstitution method, passing it a reference to the desired substitution method callback.

  • Add a <> control to the page at the desired location, and set its methodName attribute to the name of the callback method.

Learn more on ASP.NET interview questions


From more on author’s blog related to ASP.NET interview questions click and visit.

ASP.NET Interview Questions: - Show Post Cache substitution?

This is one of the asked ASP.Net Interview Questions during the Interview by the Interviewer.
Post cache substitution is used when we want to cache the whole page but also need some dynamic region inside that cached page. Some examples like QuoteoftheDay, RandomPhotos, and AdRotator etc. are examples where we can implement Post Cache Substitution.
Post-cache substitution can be achieved by two means:

Figure: - “Writesubstitution” in action
You can see we have a static function here “GetDateToString()”. We pass the response substitution callback to the “WriteSubstitution” method. So now, when ASP.NET page framework retrieves the cached page, it automatically triggers your callback method to get the dynamic content. It then inserts your content into the cached HTML of the page. Even if your page has not been cached yet (for example, it's being rendered for the first time), ASP.NET still calls your callback in the same way to get the dynamic content. So you create a method that generates some dynamic content, and by doing so you guarantee that your method is always called, and it’s content is never cached.
Ok the above example was by using “WriteSubstitution” now lets try to see how we can do by using “<>” control. You can get the “<>” control from the editor toolbox.
Figure: - Substitution Control
Figure: - Substitution in Action
Below is a sample code that shows how substitution control works. We have ASPX code at the right hand side and class code at the behind code at the left hand side. We need to provide the method name in the “methodname” attribute of the substitution control.
View following video on Web.config transformation in ASP .Net: -

Learn more on ASP.NET interview questions
From more on author’s blog related to ASP.NET interview questions click and visit.

Friday, April 26, 2013

SQL Server Interview Question and answers:- Triggers, Instead of triggers, after triggers, inserted and deleted tables?

Triggers are special kind of stored procedure which have logic's.These logics can be executed after or before data modification happens on a table.There are two types of triggers “Instead of triggers" and "After triggers".

Instead of triggers logic executes prior to data modification while after trigger logic executes after data modification.

In what scenarios will you use instead of trigger and after trigger?

You will use "INSTEAD trigger" to take alternative actions before the update happens.

Some of the uses of instead of trigger's are:-
•Reject updates which are not valid.
•Take some alternative action if any error occurs.
•To implement cascading deletes.For instance you want to delete a customer record.But in order to delete the customer record you also have to delete address records. So you can create a instead of trigger which will first delete the address table before executing delete on customer table.

While "AFTER trigger" is useful when you want to execute trigger logic after the data has been updated.

Some uses of after triggers are:-

•For recording Audit trail where you want new and old values to be inserted in to audit table.
•Updating values after the update has happened.For instance in a sales table if number of products and per product is inserted, you can create an after trigger which will calculate the total sales amount using these two values.

What are inserted and deleted tables?

During triggers we sometimes need old and new values.Insert and deleted tables are temporary tables created by SQL server itself which have new and old values.Inserted tables have one record for newly added data and deleted table has one record of the old version of the data.

So for instance let's say we add a new record called as "Shiv". The inserted table will have "Shiv" and deleted table will have nulls because the record did not exist.Now let’s say some user updates "Shiv" to "Raju".Then inserted table will have "Raju" and deleted tables will have "Shiv".

Also watch my most asked SQL Server interview question video on:- What is the difference between clustered and non-clustered indexes?

Taken from the best selling SQL Server interview question book,you can see more about the book by clicking on  SQL Server interview questions book.

What is BI Semantic model (BISM) in SQL Server 2012?

Some days back I was installing SQL Server 2012 enterprise service pack 1. During installation when I was running through the setup, it gave me two options (multi-dimensional and tabular) of  how I want to install SQL Server analysis service. Below is the image captured while doing installation.

At the first glance these options are clearly meant to specify how we want the model design for our analysis service.

No the first option i.e. "MultiDimensional" was pretty clear as I have been using them right from SQL server 2005 till today i.e. (Star schema or Snow flake).

After some googling and hunting I came to know about the second option. Let me through some light on the same and then we will conclude what is BISM.

Now over all we have two kinds of database systems, one is OLTP system where the database design thought process is in terms of tables and normalization rules ( 1 normal form , second normal form and third normal form database design ) are followed.

The second kinds of systems are OLAP system's where we mostly design in terms of fact tables and dimension tables. Cube which is a multi-dimensinal view of data is created properly if you design your database as OLAP system.

Sin simple words we need to create a DB with OLAP design to ensure that proper cubes structure is created.

Now some times I will say many times it's really not feasible to create different structure and then create cubes from them. It would be great if SSAS gives us some options where we can do analysis straight from normalized simple tables

For instance take simple end users who use "Power Pivot". It's very difficult for them to make understand OLAP models like dimension and fact tamles. But yes they do understand tables with rows and columns. If you see microsoft excel the format is in terms of table which have rows and columns and these end users are comfortable with a tabular structure.

Below is a simple image of how simple end users visulize data in excel i.e. tabular - rows and columns.

That's where exactly the second option i.e. the "tabular" mode comes in to picture.

So if we put in simple words BISM (Business intelligence semantic model) is a model which tries to serve simple user / programmers who are comfortable with tabular structure and also maintains professional OLAP  models for corporate.

So BISM is a unifying name for both Multi-dimension and tabular models. So if you are personal BI person who loves ADHOC analysis, you can use power pivot or SSAS tabular IDE to do analysis. And if you are person who is working on a corporate project then Multi-dimension model is more scalable and worth looking in to.

Just alast quick note this is also a favorite SQL Server interview question which is making round now a days when SQL Server 2012 topic is discussed.

With all due respect to my publisher Ihave taken the above answer from my book SQL Server interview questions and answers.

You can also see my blog which has some important for SQL Server interview questions on Colaesce.

You can also see my video on Can views be updated (SQL Server interview questions)?



C# interview questions and answers: - What is the difference between “==” and .Equals()?

When we create any object there are two parts to the object one is the content and the other is reference to that content.

So for example if you create an object as shown in below code:-
  1. “.NET interview questions” is the content.
  2. “o” is the reference to that content.

 “==” compares if the object references are same while “.Equals()” compares if the contents are same.

So if you run the below code both “==” and “.Equals()” returns true because content as well as references are same.

object o = ".NET Interview questions";
object o1 = o;

Console.WriteLine(o == o1);


Now consider the below code where we have same content but they point towards different instances. So if you run the below code both “==”   will return false and “.Equals()”  will return true.

object o = ".NET Interview questions";
object o1 = new string(".NET Interview questions".ToCharArray());

Console.WriteLine(o == o1);


When you are using string data type it always does content comparison. In other words you either use “.Equals()” or “==” it always do content comparison.

Enjoy this awesome youtube play list which covers 12 important .Net and c# interview question videos

You can also refer our blog which has more than 1000 .NET and c# interview questions with answer

Also see the following c# interview question video on Difference between == VS .Equals():-

Wednesday, April 10, 2013 :- Learn SharePoint Step by Step Videos is like a family to me. So when they announced which is a extension arm ( I hope I am not wrong) of for videos , I was overexcited.

So here are my three videos on Sharepoint 2010. These three videos will help you to get to speed with sharepoint.

Note :- I have a typical Indian accent  and English is my second language. So if my accent hurts your ears , sorry for it.

In the first video I have explained basics like Sharepoint and Sharepoint foundation. This video is a warm-up video where I have talked about benefits of sharepoint and what are the pre-requisites for installing sharepoint.

In the second video I have wasted no time and I started creating a small portal using sharepoint. While creating this portal we will also go through different sharepoint concepts like Webapplications,Site collection,Site , pages and List. While creating the portal we will take help of custom fields and content types to collect end user data.

This third video is an extension of second video. The second video was almost 25 minutes so I broken down the videos in two parts.

This is my first experiment with and I wish Chris and Sean the best for their new venture.

c# interview questions and answers :- What is the use of c# “Yield” keyword.

What is the use of “Yield” keyword?

“Yield helps you to provide custom stateful iteration over .NET collections.”

There are two scenarios where “yield” keyword is useful:-

  • Customized iteration through a collection without creating a temporary collection.
  •  Stateful iteration.

Scenario 1:- Customized iteration through a collection

Let’s try to understand what customized iteration means with an example. Consider the below code.

Let say we have a simple list called as “MyList” which has collection of 5 continuous numeric values 1,2,3,4 and 5. This list is browsed/iterated from  console application from within static void main method.

For now let’s visualize the “main()” method as a caller. So the caller i.e.  “main()” method calls the list and displays the items inside it.  Simple…till now ;-).

static List<int> MyList = new List<int>();

static void FillValues()

static void Main(string[] args) // Caller
            FillValues(); // Fills the list with 5 values
            foreach (int i in MyList) // Browses through the list

Now let me complicate this situation let’s say the caller only wants values greater than “3” from the collection.  So the obvious thing as a c# developer we will do is create a function as shown below. This function will have temporary collection. In this temporary collection we will first add values which are greater than “3” and return the same to the caller. The caller can then iterate through this collection.

static IEnumerable<int> FilterWithoutYield()
            List<int> temp = new List<int>();
            foreach (int i in MyList)
                if (i > 3)
            return temp;

Now the above approach is fine but it would be great if we would get rid of the collection, so that our code becomes simple. This where “yield” keyword comes to help. Below is a simple code how we have used yield.

“Yield” keyword will return back the control to the caller, the caller will do his work and re-enter the function from where he had left and continue iteration from that point onwards. In other words “yield” keyword moves control of the program to and fro between caller and the collection.

static IEnumerable<int> FilterWithYield()
            foreach (int i in MyList)
                if (i > 3) yield return i;

So for the above code following are details steps how the control will flow between caller and collection. You can also see the pictorial representation in the next diagram shown below.
  • Step 1:- Caller calls the function to iterate for number’s greater than 3.
  • Step 2:- Inside the function the for loop runs from 1 to 2 , from 2 to 3 until it encounters value greater than “3” i.e. “4”. As soon as the condition of value greater than 3 is met the “yield” keyword sends this data back to the caller.
  • Step 3:- Caller displays the value on the console and re-enters the function for more data. This time when it reenters, it does not start from first. It remembers the state and starts from “5”. The iteration continues further as usual. 

Scenario 2:- Stateful iteration
Now let us add more complications to the above scenario. Let’s say we want to display running total of the above collection. What do I mean?.

In other words we will browse from 1 to 5 and as we browse we would keep adding the total in variable. So we start with “1” the  running total is “1”, we move to value “2” the running total is previous value “1” plus current value “2” i.e. “3” and so on.

Below is the pictorial representation of the running total looks like.

In other words we would like to iterate through the collection and as we iterate would like to maintain running total state and return the value to the caller ( i.e. console application). So the function now becomes something as shown below. The “runningtotal” variable will have the old value every time the caller re-enters the function.

static IEnumerable<int> RunningTotal()
            int runningtotal=0;
             int index=0;
             foreach(int i in MyList)
                 index = index + 1;
                 runningtotal = i;
                  runningtotal = i + runningtotal;
                 yield return (runningtotal);

Below goes the caller code and output.

foreach (int i in RunningTotal())

You can also visit my site for c# interview questions with answers .In addition to my site recently I have also created a blog c#interview questions and answers