Sunday, December 30, 2012

Lock keyword in C#

As we have written earlier we have now multi-core CPU for our computers and laptops and to utilize that we need to use threading in code. Now if we create thread and access same resource at same time then it will create a problem at that time locking become quite essential in any programming language.

Let’s consider a scenario. We are having a small firm of computers and each computer is shared by two employees and they need to use computer for putting their sales data in excel sheet. So they can not work together at same time and one has to work and other has to wait till first one complete the work. Same situation can be occurred in programming in where we are using same resource for multiple thread.

C# provides locking mechanism via lock keyword. It restricts code from being executed by more then one thread at a time. That is the most reliable way of doing multi threading programming.
Share:
Thursday, December 27, 2012

Merry Christmas to all my readers

This is not a usual technical post I am writing here. I just wanted to take a moment and wishing you Merry Christmas and happy holidays. All readers are has been great support to this blog and on this occasion I want thank you guys for all the support and love you have shown during this year 2012. I have achieved so much through this blog and its been not possible without your support.

I wish that year 2013 will bring you all joy and happiness you required. May all your wishes fulfil.

MerryChristmas

Stay tuned for more. I have lots of stuff for you in 2013. Till then happy holidays!! and once Merry Christmas to you and your family.
Share:
Friday, December 21, 2012

Where I can find SQL generated by Linq-To-SQL

Yesterday I have written a blog post about Where I can find SQL Generated by Entity Framework? and same day I got request from one of the our reader Ramesh that how I can find SQL generated by Linq-To-SQL?. I thought its a good idea to write a blog post to share amongst all who need this instead of reply in comments.  In this post I am going to explain how we can get SQL generated by Linq-To-SQL.

For this post I am going to use same table like following. A customer table with two columns CustomerId and CustomerName.

How to get SQL staement generated by Linq-To-SQL
Share:
Thursday, December 20, 2012

Where I can find SQL Generated by Entity framework?

Few days back I was optimizing the performance with Entity framework and Linq queries and I was using LinqPad and looking SQL generated by the Linq or entity framework queries. After some point of time I got the same question in mind that how I can find the SQL Statement generated by Entity framework?

After some struggling I have managed to found the way of finding SQL Statement so I thought it would be a great idea to write a post about  same and share my knowledge about that. So in this post I will explain how to find SQL statements generated Entity framework queries.

To demonstrate the idea Let’s a very simple console application with C# and then  create a table called ‘Customer’ with CustomerId and CustomerName field in sql server.
Share:
Tuesday, December 18, 2012

Caller Info Attributes in C# 5.0

In c# 5.0 Microsoft has introduced a Caller information attribute. It’s a new feature that is introduced in C# 5.0 and very useful if you want to log your code activities. With the help of this you can implement the log functionality very easily. It can help any programmer in tracing, debugging and diagnostic of any application.
With the help of Caller Information we can get following information over there.

  1. CallerFilePathAttribute: With help of  this attribute we can get full path of source file that contains caller. This will be file path from which contains caller at compile time.
  2. CallerLineNumberAttribute:  With the help of this attribute we can get line number of source file which the method is called.
  3. CallerMemberNameAttribute: With the help of this attribute we can get the method or property name of the caller.

Let’s write a simple example for that to see how its works. Following is a code for that.
Share:
Sunday, December 16, 2012

Parallel task in C# 4.0

In today’s computing world  is all about Parallel processing. You have multicore CPU where you have different core doing different work parallel or its doing same task parallel. For example I am having 4-core CPU as follows. So the code that I write should take care of this. C# does provide that kind of facility to write code for multi core CPU with task parallel library. We will explore that in this post.

Parrallel Task in C# 


Share:
Sunday, December 2, 2012

Dynamic URL of asp.net web service with web reference

It’s been a while I am writing this. But never late.. So I am writing this. Before some time one of friend asked about the URL of web service when we add reference. So I am writing this. Some of you may find this very basic but still many of people does not know this that’s why I am writing this.

In today’s world we have so many servers like development, preproduction and production etc. and for all the server location or URL of web service will be different.But with asp.net when you add a web reference to your web application it’s create a web reference settings in web.config where you can change this path. So it’s very easy to just change that path and you don’t have to add web reference again.
Share:
Wednesday, October 10, 2012

Dark Visual Experience in Visual Studio 2012

I have written whole series related to Visual Studio 2012 features and this post will also be part of same series.You can get all my post related to visual studio from the following link.

Visual Studio 2012 feature series

Before some days I was searching something and found a great way to change the visual experience of visual studio 2012. I found that there are two type of themes available in visual studio 2012 light and dark under Tools->Option-> General environment value. This is one of newest feature I have found in visual studio 2012.

Dark Visual Experience in Visual studio 2012- A new visual studio feature.
Share:
Wednesday, September 12, 2012

Tips for increasing Alexa rank of your technical blog

Today I am not writing any technical post. This post is out of subject for this technical blog. But the intension of this blog to reach more and more people to help community so I am writing this. In this post I am going to explain few tips for improving Alexa rank for your technical blog.

What is Alexa Rank?


Alexa.com is a private company founded in 1996. They defined themselves as the “Web information company”. But in simple words for us Alexa is a company that measures web traffic in almost every site on the internet through their toolbar plugin. On the internet Alexa rank becomes a standard in the webmasters world. If you have good Alexa ranking then there will more people,advertisers,sponsors and visitors will be attracted your site.

Tips for increasing Alexa rank on your technical blog:


I am not kind of guru on this. I am just sharing what I have learnt from the experience. Followings are few tips that will help you increasing Alexa rank.

  1. First thing I need to clear that alexa rank and google page rank are both different. So If you are having higher page rank that does not mean that you will have higher Alexa rank. Both are measured in different way.
  2. To have perfect Alexa rank first thing you need to is to claim your site at Alexa.com. You can claim your site via putting a meta tag suggested by them. That way Alexa.com can access your site better and you could have possibly better and accurate rank over there.
Share:
Saturday, September 8, 2012

Predicate delegate in C#

I am writing few post on different type of delegates and this post also will be part of it. In this post I am going to write about Predicate delegate which is available from C# 2.0. Following is list of post that I have written about delegates.

  1. Delegates in C#.
  2. Multicast delegates in C#.
  3. Func delegate in C#.
  4. Action delegate in C#.

Predicate delegate in C#:

As per MSDN predicate delegate is a pointer to a function that returns true or false and takes generics types as argument. It contains following signature.

Predicate<T> – where T is any generic type and this delegate will always return Boolean value. The most common use of a predicate delegate is to searching items in array or list. So let’s take a simple example. Following is code for that.
Share:
Thursday, September 6, 2012

Action delegates in C#

In last few posts about I have written lots of things about delegates and this post is also part of that series. In this post we are going to learn about Action delegates in C#.  Following is a list of post related to delegates.

  1. Delegates in C#.
  2. Multicast Delegates in C#.
  3. Func Delegates in C#.

Action Delegates in c#:

As per MSDN action delegates used to pass a method as parameter without explicitly declaring custom delegates. Action Delegates are used to encapsulate method that does not have return value. C# 4.0 Action delegates have following different variants like following. It can take up to 16 parameters.

  • Action – It will be no parameter and does not return any value.
  • Action(T)
  • Action(T1,T2)
  • Action(T1,T2,T3)
  • Action(T1,T2,T3,T4)
  • Action(T1,T2,T3,T4,T5)
  • Action(T1,T2,T3,T4,T5,T6)
  • Action(T1,T2,T3,T4,T5,T6,T7)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15)
  • Action(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16)
Share:
Wednesday, September 5, 2012

Incremental search in Visual Studio

Visual studio is a Great IDE and there are still lots of feature that not known to developers. Incremental search is one of them. This is a amazing feature to find code in particular document and its available from Visual Studio 2010 and carried over in Visual Studio 2012. Incremental search allows developers to search in document without blocking UI and allow to search as they type.

Interesting!! right.. So let’s open visual studio and see how it works. Once you open Visual Studio and press Ctrl + I and type something it will find the string without blocking your visual studio UI. Just like following.

Incremental Search in Visual Studio
Share:
Saturday, August 25, 2012

Func Delegate in C#

We already know about delegates in C# and I have previously posted about basics of delegates in C#. Following are posts about basic of delegates I have written.

Delegates in C#
Multicast Delegates in C#

In this post we are going to learn about Func Delegates in C#. As per MSDN following is a definition.

“Encapsulates a method that has one parameter and returns a value of the type specified by the TResult parameter.”

Func can handle multiple arguments. The Func delegates is parameterized type. It takes any valid C# type as parameter and you have can multiple parameters as well you have to specify the return type as last parameters.

Followings are some examples of parameters.
Func<int T,out TResult>
Func<int T,int T, out Tresult>

Now let’s take a string concatenation example for that. I am going to create two func delegate which will going to concate two strings and three string. Following is a code for that.

using System;
using System.Collections.Generic;

namespace FuncExample
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string, string, string> concatTwo = (x, y) => string.Format("{0} {1}",x,y);
            Func<string, string, string, string> concatThree = (x, y, z) => string.Format("{0} {1} {2}", x, y,z);

            Console.WriteLine(concatTwo("Hello", "Jalpesh"));
            Console.WriteLine(concatThree("Hello","Jalpesh","Vadgama"));
            Console.ReadLine();
        }
    }
}

Share:
Friday, August 24, 2012

What is Inversion of control and why we need it?

Most of programmer need inversion of control pattern in today’s complex real time application world. So I have decided to write a blog post about it. This blog post will explain what is Inversion of control and why we need it. We are going to take a real world example so it would be better to understand.

The problem- Why we need inversion of control?


Before giving definition of Inversion of control let’s take a simple real word example to see why we need inversion of control. Please have look on the following code.

public class class1
{
    private class2 _class2;

    public class1()
    {
       _class2=new class2();
    }

}
public class class2
{
     //Some implementation of class2
}

I have two classes “Class1” and “Class2”.  If you see the code in that I have created a instance of class2 class in the class1 class constructor. So the “class1” class is dependent on “class2”. I think that is the biggest issue in real world scenario as if we change the “class2” class then we might need to change the “class1” class also. Here there is one type of dependency between this two classes that is called Tight Coupling. Tight coupling will have lots of problem in real world applications as things are tends to be change in future so we have to change all the tight couple classes that are dependent of each other. To avoid this kind of issue we need Inversion of control.
Share:
Friday, August 17, 2012

IUnlockJoy I build amazing Windows Phone Apps event –11th August rocks!!

Last Saturday ,11th August Microsoft and Ahemdabad .NET user group has organized the IUnlockJoy I build amazing Windows Phone Apps  event. It was first in india as IUnlockJoy campaign was just launched by Microsoft before 3 days. It was superb and well organized thanks to Dhola Mahesh, Prabjhot Baxi,Kaushal Bhavasar and Pranjal Nigam.



It was a great event with almost 100+ people during holiday. Event was started by a keynote speaker Mahesh Dhola. He introduced IUnlockJoy- I build amazing Windows Phone Apps campaign and some of benefits of it.


VIS_8584

After his session Prabjhot singh Baxi has taken a session about how you can get best out of windows phone. He has describe all the process from opening a developer account to publish an app to market place. The session was full of information and I really enjoyed it.
Share:
Saturday, July 28, 2012

Multiple file upload with asp.net mvc and HTML5

Few days I have written a blog post about Multiple file upload with asp.net 4.5 and Visual studio 2012. It was greatly appreciated by the community and also been part of www.asp.net community daily spot light.  On that post one of my reader Ciwan Kurd has requested the asp.net mvc version of that post. So in this post I will explain how we can do multiple file upload with HTML5.

For this post I am going to use asp.net mvc 3 with HTML5 template and visual studio 2012 but you can use same techniques in any version of asp.net mvc.  First things we needs to do create a HTML form for the uploading file in asp.net mvc view so following is a code for that.

@using (Html.BeginForm("Upload", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{ 
    <label for="file">Upload Image:</label>
    <input type="file" name="files" value="" multiple="multiple"/>
    <input type="submit" value="Upload Image" />
}

In above code that I have use @HTML.BeginForm to create a HTML form with multipart as this attribute is required to upload any kind of files on the server. I have mapped that form to upload action result. Also I have used the file input control with HTML5 multiple attribute which allow us to upload multiple files on the server. Now its time to write code in asp.net mvc controller. Following is a code for that.
Share:
Tuesday, July 17, 2012

Why we should write blogs and do community work

I am doing blogging since last 5 years and I have seen lots of people asking the same things. Why do you write blog? do you have any side income for this blog? Why you are so active in community ? I am answering this questions almost every day. So I decided to write a blog post about it. Following are the reason why I am writing blogs and doing community work?

Help:

I like to help people and that is one of the main reason behind the all blogs and community work. Also helping other is a great way to learn new things. Because other person may be facing a problem which you never encountered during your professional life or project you are doing!!. At the end of you can feel proud that you help somebody.

Learning:

I have to learn lots of things everyday to write my blogs. Some one said Teaching some one is best way to learn new things. It apply here also when you write blog or answer question on forum.

Earn Award and Get famous:

This is one of the advantages of writing blogs and doing community things. People will know that you are having such knowledge in respected fields. I have got Microsoft Most Valuable Professional award 3 times due to my blogging and community work. But remember one thing your first intension of doing communication work is to help people. All other things will come as other benefits.

Communication skills:

Once you communicate with lots of people and write blog it will definitely increase your communication skills. If you are writing some blogs then its going to increase your writing skills also.
Share:

Model binding with ASP.NET 4.5 and Visual Studio 2012

Note:I have written a whole series of Visual Studio 2012 features and this post will also be part of same series. You can get the whole list of blogs/articles from the Visual studio 2012 feature series posts there. Following is a link for that.Visual Studio 2012 feature series
In earlier version of the asp.net we have to bind controls with data source control like SQL Data source, Entity Data Source, Linq Data Source if we want to bind our server controls declaratively. Some developers prefer to write whole data access logic and then bind the data source with databind method. Model binding is something similar to asp.net mvc binding.

Model Binding in ASP.NET 4.5 and Visual Studio 2012:


With ASP.NET 4.5 and Visual studio 2012 we have a new method of binding data called ‘ Model binding’. It’s a code focus approach of data binding. Now all the controls will have ItemType property which will implement strongly type binding. The server controls will then call appropriate methods at the proper time in page life cycle and bind the data.

So what we are waiting for ? let’s take one example. First we need to create a model. For the this I have created a model class called ‘Customer’. Following is code for that.
Share:
Thursday, July 12, 2012

Free Visual Studio 2012 eBook from Telerik

Note:I have been writing lots of things about Visual Studio 2012 and this post is same in the series. You can find complete list of post from the following link.Visual Studio 2012 feature series- What’s new in Visual Studio 2012.
Visual studio 2012 is there in RC stage and I am exploring that into the great extent. Visual Studio 2012 is great editor there is no doubt. It is much more mature and comes with lots of features. Telerik – A well know in third party controls released a free eBook on Visual Studio 2012 and ASP.NET 4.5. You can find lots of time saving feature documented in this eBook.

Visual Studio 2012 feature list - What's new in Visual Studio 2012

Following is a quick list of features they have explored in Visual Studio 2012.
  1. JavaScript Intellisense
  2. CSS Intellisense
  3. ASP.NET and ASP.NET Web API
  4. Strongly typed data binding
  5. Page Inspector(new Debugging Tool)
  6. HTML5 and CSS3 is available out of box
  7. Request validation prevents yellow screen of death
  8. WAI Aria makes the web usable by all
Share:
Saturday, July 7, 2012

Dividing web.config into multiple files in asp.net

When you are having different people working on one project remotely you will get some problem with web.config, as everybody was having different version of web.config. So at that time once you check in your web.config with your latest changes the other people have to get latest that web.config and made some specific changes as per their local environment. Most of people who have worked things from remotely has faced that problem. I think most common example would be connection string and app settings changes.

For this kind of situation this will be a best solution. We can divide particular section of web.config into the multiple files. For example we could have separate ConnectionStrings.config file for connection strings and AppSettings.config file for app settings file.

Most of people does not know that there is attribute called ‘configSource’ where we can  define the path of external config file and it will load that section from that external file. Just like below.

<configuration>
 <appSettings configSource="AppSettings.config"/>
 <connectionStrings configSource="ConnectionStrings.config"/>
</configuration>

And you could have your ConnectionStrings.config file like following.
Share:
Tuesday, July 3, 2012

Event handler generation in Visual Studio 2012

Note: This post will be a part of Visual Studio 2012 feature series.
There are lots of new features there in visual studio 2012. Event handler generation is one of them. In earlier version of visual studio there was no way to create event handler from source view directly.  Now visual studio 2012 have event handler generation functionality.

So if you are editing an event view in source view intellisense will display add new event handler template and once you click on it. It will create a new event handler in the cs file. It will also put a eventhandler name against event name so you don’t need to write that.

So, let’s take a simple example of button click event so once I write onclick attribute their smart intellisense will pop up
.
Event handler generation in visual studio 2012 - What's new in visual studio 2012

Now once you click on <Create New Event> It will create event handler in .cs file like following.
Share:
Monday, July 2, 2012

Multiple file upload with asp.net 4.5 and Visual Studio 2012

Note: This post will be part of Visual Studio 2012 feature series.
In earlier version of ASP.NET there is no way to upload multiple files at same time. We need to use third party control or we need to create custom control for that. But with asp.net 4.5 now its possible to upload multiple file with file upload control.

With ASP.NET 4.5 version Microsoft has enhanced file upload control to support HTML5 multiple attribute. There is a property called ‘AllowedMultiple’ to support that attribute and with that you can easily upload the file. So what we are waiting for!! It’s time to create one example.
On the default.aspx file I have written following.

<asp:FileUpload ID="multipleFile" runat="server" AllowMultiple="true" />
<asp:Button ID="uploadFile" runat="server" Text="Upload files" onclick="uploadFile_Click"/>

Here you can see that I have given file upload control id as multipleFile and I have set AllowMultiple file to true. I have also taken one button for uploading file.For this example I am going to upload file in images folder. As you can see I have also attached event handler for button’s click event. So it’s time to write server side code for this. Following code is for the server side.

protected void uploadFile_Click(object sender, EventArgs e)
{
    if (multipleFile.HasFiles)
    {
        foreach(HttpPostedFile uploadedFile in multipleFile.PostedFiles)
        {
            uploadedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Images/"),uploadedFile.FileName));
            Response.Write("File uploaded successfully");
        }
    }
}

Share:
Sunday, July 1, 2012

Third year in a row- Microsoft MVP again!!

Today is Sunday and I was not expecting this as today is holiday although I know it was Microsoft Mvp renewal day. At evening I got the congratulation email from the Microsoft. Yeah!! I am Microsoft Most Valuable Professional again. I got the same message as a part of Mvp. Thanks Microsoft again.

Dear Jalpesh Vadgama,
Congratulations! We are pleased to present you with the 2012 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in Visual C# technical communities during the past year.


Feeling is again same as first time. I am going to dedicated this award to my family. My parents who always inspired me to do new things. My wife who scarifies her time to write blogs. My brother who support me in every possible way.

On this occasion, I would also like to thanks my reader without their support it was no possible to achieve this. Thanks for reading my blog!!. Please do keep reading this.
I will try to write as much as possible.

I would also like to thanks ‘Tanmay Kapoor’ My Mvp lead for continuous support. 

Share:

Quick tour of visual studio 2012 features so far

Note: I am writing a whole new feature series about Visual Studio 2012 new features. Following is the link for that. I have written couple of post there.Visual Studio 2012 features series. What's new in Visual Studio 2012
I thought it would be great idea to write summary post for this. So this post will be a summary of all the post I have written so far. Here it will describes what’s new in visual studio 2012 and what are the features that I have covered so far. It will be quick of tour of some of the feature in Visual Studio 2012.

Visual studio 2012 first review(Earlier known as Visual studio 2011 beta)


In this post, I have written about the Metro UI of visual studio 2012. It’s totally different then the older version of visual studio 2012. Now its empathize more on code instead of visual appealing things. In this blog post I have also described solution explorer and tool box features also. Following is a link for that.

Visual Studio 2011 Beta First Review(Now known as Visual Studio 2012)

Project dialog box changes in visual studio 2012


In this post, I have written about Project dialog box changes and also written about new project templates which are included in the project dialog like ‘Portable Class Library’. I have also explained some of new other additions in project template like ‘Light switch category’ and ‘Coded UI test project’ in visual studio 2012. Following is a link for that post.
Share:
Wednesday, June 27, 2012

Interview questions about ASP.NET Web services.

I have seen there are lots of myth’s about asp.net web services in fresher level asp.net developers. So I decided to write a blog post about asp.net web services interview questions. Because I think this is the best way to reach fresher asp.net developers. Followings are few questions about asp.net web services.

1) What is asp.net web services?
Ans: Web services are used to support http requests that formatted using xml,http and SOAP syntax. They interact with through standards xml messages through Soap. They are used to support interoperability. It has .asmx extension and .NET framework contains http handlers for web services to support http requested
directly.


2) What kind of data can be returned web services web methods?
Ans: It supports all the primitive data types and custom data types that can be encoded and serialized by xml. You can find more information about that from the following link.
http://msdn.microsoft.com/en-us/library/bb552900.aspx

3) Is web services are only written in asp.net?
Ans: No, It can be written by Java and PHP languages also.

Share:

Bundling in visual studio 2012 for web optimization

Note: I have been writing a series of posts about Visual Studio 2012 features. This series describes what are the new features in the Visual Studio 2012. This post will also be part of Visual Studio 2012 feature series.
As we know now days web applications or site are providing more and more features and due to that we have include lots of JavaScript and CSS files in our web application.So once we load site then we will have all the JavaScript  js files and CSS files loaded in the browsers and If you have lots of JavaScript files then its consumes lots of time when browser request them.
Following images show the same situation over there.

Bundling feature in Visual Studio 2012 - Visual Studio 2012 feature series

Here you can see total 25 files loaded into the system and it's almost more than 1MB of total size. As we need to have our web application of site very responsive and need to have high performance application/site, this will be a performance bottleneck to our site. In situation like this, the bundling feature of Visual Studio 2012 and ASP.NET 4.5 comes very handy. With the help of this feature we do optimization there and we can increase performance of our application.
Share:
Friday, June 22, 2012

Why C# does not support multiple inheritance?

Yesterday, One of my friends, Dharmendra ask me why C# does not support multiple inheritance. This is the question most of the people ask every time. So I thought it will be good to write a blog post about it. So why it does not support multiple inheritance?

I tried to dig into the problem and I have found the some of good links from C# team from Microsoft for why it’s not supported in it. Following is a link for it.

http://blogs.msdn.com/b/csharpfaq/archive/2004/03/07/85562.aspx


Also, I was giving some of the example to my friend Dharmendra where multiple inheritance can be a problem.The problem is called the diamond problem. Let me explain a bit. If you have class that is inherited from the more then one classes and If two classes have same signature function then for child class object, It is impossible to call specific parent class method.
Share:
Thursday, June 21, 2012

Color indication in Visual Studio 2012

Note: This post will be a part of Visual Studio 2012 series.
Before some days Microsoft has released the release candidate version of Visual Studio 2012. Today I got installed Visual Studio 2012 and once I loaded the visual studio 2012 first things I noticed that there is purple color blank strip is there at bottom. After doing some R and D on internet I have found that it is used for the different indication. The purple color indicates that there is no project loaded now.

Color Indication in visual studio 2012 Purple color for no project
Share:
Friday, May 25, 2012

ASP.NET Web API Basics

We have seen that now web is really becoming cross plate form and you can see your services or API can be exposed to any client. Till now one of big challenges is to choose platform for this kind of service. There are so many options available like web services, WCF services,Generic Handlers, directly writing responses on aspx page etc. There are plenty of options available and each one has their own pros and cons.  But now we have one simpler answer for that is ASP.NET Web API.

What is Web API?

ASP.NET Web API is a framework for building web API on the top of .NET framework. It’s a framework for building and consuming web services that can be use at broad range of clients like browsers,tablets phones etc. You can expose JSON or XML whatever you want to use.

Why to use Web API?

Think about a situation where a jQuery script that is making a ajax request and we need some thing who can expose data from the server to the client at that time WEB API can be very handy you can expose server data in XML or JSON form and you can make that call with simple http request. No lengthy code required to call WEB API.
Share:
Thursday, May 24, 2012

Extract to User Control in visual studio11

Note: This post will be part of Visual Studio 2012 feature series. As Visual studio 2011 beta is now known as Visual Studio 2012
I have been playing with Visual Studio 11 beta recently and everyday I am amazed with new features of it. Today I have found one more very useful feature Extract to User Control feature.

In large projects, we are having large pages and its always good to use  user control(.ascx) but sometimes we are so lazy to create user controls and we remain with the whole page and even we can’t reuse that code. In similar kind of situation ‘Extract to user control’ can be quite useful. Suppose we have long HTML mark up and we need to convert one div to user control and then we can do it very easily with Visual Studio 11 beta Extract to User Control feature.

You just need to select code you want there in user control and then you need to right click and click ‘Extract to User Control’ like below.

Extract to user control feature- What's new in visual studio 11 features
Share:
Wednesday, May 23, 2012

Browser selection in Visual Studio 11

This blog post will be a part of Visual Studio 2012 features series. As now Visual Studio 2011 beta know as Visual Studio 2012.

In the earlier version of the Visual Studio if you want to run your page in browser then you have to do it with view in browser. But now you have directly that on the Visual studio 2012 toolbar like below.

Visual Studio 2011 beta Broswer selection toolbar

Share:
Thursday, May 10, 2012

Image preview in solution explorer Visual Studio 2011 beta

Note: This post will be part of Visual Studio 2012 feature series. As Visual Studio 2011 beta is known as Visual Studio 2012.

Everyday I am using Microsoft Visual Studio 2011 beta and everyday I learn some cool feature of it. In today’s post I am going to explain one cool features of Visual Studio 2011 beta solution explorer. As a web developer we all want to see the image preview in solution explorer and visual studio 2011 beta is now having it. We can see image preview in solution explorer just like following.
Share:
Tuesday, May 8, 2012

Css Enhancement in Visual Studio 2011 beta

Note:This blog post will be part of Visual Studio 2012 feature series.As now visual studio 2011 beta is known as Visual Studio 2012.
In this post we are going to look at some of CSS enhancement features in Visual Studio 2011 beta. First thing you notice in Visual Studio 2011 is better intellisense for the CSS. Now same kind of intellisense are available which we are using for C# and other languages.

Better CSS Intellisense in Visual Studio 2011 Beta- Features of Visual Studio 2011

Another enhancement is color selection Visual Studio 2011 beta. Now it’s provides a Great Color picker to choose CSS colors as you want. You don’t have to rely on the Hexadecimal value for color.

image

Commenting and uncommenting in CSS is now very easy and can you with formatting toolbar like following.

Commenting and uncommenting features in Visual Studio 2011 beta

That’s it. Hope you liked it. Stay tuned for more..Till than happy programming.
Share:
Sunday, May 6, 2012

Go to definition in JavaScript feature of Visual Studio 2011 beta

Note: Now Visual Studio 2011 beta is officially released as Visual Studio 2012. So it will be part of Visual Studio 2012 series.

In recent days I am exploring the Visual studio features and this blog post is also part of that. I am loving visual studio 2011 beta more and more after exploring features that make developer’s life easy. Today I am going to talk about one of the features that is going to make developer’s life easy.

JavaScript is a client scripting language which is an integral part of any web application now days.  So if you are web application developer you are surely going to write lots of JavaScript those days.  With earlier version of visual studio navigating code in JavaScript is not easy. But in visual studio 2011 beta we have go to definition features which one of most favourite features of visual studio for visual C#.
Share:
Saturday, May 5, 2012

Project Dialog in Visual Studio 2011 beta

This post will be a part of the Visual Studio 2012 Feature Series. As now visual studio 2011 beta is known as Visual Studio 2012 .
Today we are going to look at the New project dialog and some other improvements in visual studio 2011 beta. New project dialog comes with streamlined metro style icons of the project and looks beautiful. You can see some new project templates like portable class library which is a project template for creating dlls which can run on the windows,Silverlight and windows phone 7 and Xbox 360 just like following.
Share:
Friday, May 4, 2012

Visual Studio 2011 Beta First Review.

Note:This post be a part of Visual Studio 2012 feature series. As know Visual Studio 2011 beta known as Visual Studio 2012.

Before some days Microsoft has release visual studio 2011 beta and I have started playing with it. Have you played with it yet? If not then this series of post is for your.

I am basically a developer by heart. So out of latest offering from Microsoft  I am concentrating more on Visual studio 2011,ASP.NET 4.5,C# new features and ASP.NET MVC 4. So here we got let’s load visual studio 2011 beta.
Share:
Thursday, May 3, 2012

DotNetJalps 500th blog post- A milestone achieved.

This is my 500th blog post on this blog and I feel very proud writing this blog post. I am very passionate about blogging and I have been doing more than 5 years.  500th blog post a great achievement and on this occasion first all I would like to thank my family for continuous support they are providing support to maintain blog at regular interval.
Share:

Review of 70-562exam preparation kit from uCertify

Before some time I got an offer from uCertify to review their examination kit. I was lot busy this days so was able to do early but now I have completed review of it. So the first things to do is to download preparation  kit from their website. Here is the link from where I have downloaded this.

http://www.ucertify.com/exams/Microsoft/70-562-CSHARP.html
Share:
Friday, April 20, 2012

File Upload in ASP.NET MVC3

If you are a web developer you often need to upload file on the web server or database. In today’s post I am going explain how we can upload file in ASP.NET MVC 3 with razor syntax.

So, first thing we need to create a view that will contain the file upload control. I am going to use an existing asp.net mvc template for this demo. So I have just modified the default Index view like following.
Share:
Tuesday, April 17, 2012

Difference between SkipWhile and Where in linq

Before some time I have written a blog post about the SkipWhile operator and a reader of my blog asked me that we can do the same thing with Where also but there is a difference between this two. So In this post I am going to explain you difference between those two.

Where operator filters a list of collection based on condition. It will filter whole collection while SkipWhile will only skip those elements in list until condition is true and after that it will stop filtering of skipping.Now let’s take an example where we can see the difference between Where and SkipWhile. Following is a code for that.
Share:
Monday, April 16, 2012

Tuple in C# 4.0

C# 4.0 language includes a new feature called Tuple. Tuple provides us a way of grouping elements of different data type. That enables us to use it a lots places at practical world like we can store a coordinates of graphs etc.

In C# 4.0 we can create Tuple with Create method. This Create method offer 8 overload like following. So you can group maximum 8 data types with a Tuple. Followings are overloads of a data type.
  • Create(T1)- Which represents a tuple of size 1
  • Create(T1,T2)- Which represents a tuple of size 2
  • Create(T1,T2,T3) – Which represents a tuple of size 3
  • Create(T1,T2,T3,T4) – Which represents a tuple of size 4
  • Create(T1,T2,T3,T4,T5) – Which represents a tuple of size 5
  • Create(T1,T2,T3,T4,T5,T6) – Which represents a tuple of size 6
  • Create(T1,T2,T3,T4,T5,T6,T7) – Which represents a tuple of size 7
  • Create(T1,T2,T3,T4,T5,T6,T7,T8) – Which represents a tuple of size 8
Share:
Saturday, April 14, 2012

TakeWhile operator in linq

In this post I am going to explain TakeWhile Operator in details. TakeWhile is one of partitioning operator available in Linq. It will take sequence until condition becomes false.

Here is the example for that.

using System;
using System.Collections.Generic;
using System.Linq;
namespace Linq
{
class Program
{
  static void Main(string[] args)
  {
      int[] numbers ={10,9,8,7,6,5,4,3,2,1};

      foreach(var number in numbers.TakeWhile(n=>n>5))
      {
          Console.WriteLine(number);
      }
  }
}
}


Share:

SkipWhile Method in Linq

I have been playing around linq and I have found great method call SkipWhile method. SkipWhile methods skips particular element which matches condition in predicate this can be use full in condition where we need to skip elements on particular condition.

So let’s take some example. I have written following console application code.

using System;
using System.Collections.Generic;
using System.Linq;
namespace Linq
{
  class Program
  {
      static void Main(string[] args)
      {
          string[] names = { "Jalpesh", "Jayesh", "Tushar", "Tejas", "Sanjay", "Nijesh" };
          foreach(var name in names.SkipWhile(s=>s.ToLower().StartsWith("j")))
          {
              Console.WriteLine(name);
          }
      }
  }
}

Share:

Full screen in Visual studio 2010

Visual studio is a great IDE and I am learning everyday something new and I have found one great feature today which is available from the Visual studio 2008. So I thought it would great to be share with all you guys.

We all like to have most portion of screen to cover code part so we can view all the lines and we don’t have to use page and page down keys to navigate through code. You can have visual studio in full screen mode with View->Full Screen or via pressing Shift + Alter + Enter as shortcut..
Share:
Friday, April 13, 2012

Multicast delegates in c#

In yesterday’s post We learn about Delegates and how we can use delegates in C#. In today’s blog post we are going to learn about Multicast delegates.

What is Multicast Delegates?

As we all know we can assign methods as object to delegate and later on we can call that method with the help delegates. We can also assign more then methods to delegates that is called Multicast delegates. It’s provide functionality to execute more then method at a time. It’s maintain delegates as invocation list (linked list).
Share:
Thursday, April 12, 2012

Delegates in c#

I have used delegates in my programming since C# 2.0. But I have seen there are lots of confusion going on with delegates so I have decided to blog about it. In this blog I will explain about delegate basics and use of delegates in C#.

What is delegate?

We can say a delegate is a type safe function pointer which holds methods reference in object. As per MSDN it's a type that references to a method. So you can assign more than one methods to delegates with same parameter and same return type.
Share:
Wednesday, April 11, 2012

Dynamically creating meta tags in asp.net mvc

As we all know that Meta tag has very important roles in Search engine optimization and if we want to have out site listed with good ranking on search engines then we have to put meta tags. Before some time I have blogged about dynamically creating meta tags in asp.net 2.0/3.5 sites, in this blog post I am going to explain how we can create a meta tag dynamically very easily.

To have meta tag dynamically we have to create a meta tag on server-side. So I have created a method like following.

Share:
Monday, April 9, 2012

Creating dynamic breadcrumb in asp.net mvc with mvcsitemap provider

I have done lots breadcrumb kind of things in normal asp.net web forms I was looking for same for asp.net mvc. After searching on internet I have found one great nuget package for mvpsite map provider which can be easily implemented via site map provider. So let’s check how its works. I have create a new MVC 3 web application called breadcrumb and now I am adding a reference of site map provider via nuget package like following.
Share:
Saturday, April 7, 2012

Execute TSQL statement with ExecuteStoreQuery in entity framework 4.0

I was playing with entity framework in recent days and I was searching something that how we can execute TSQL statement in entity framework. And I have found one great way to do that with entity framework ‘ExecuteStoreQuery’ method. It’s executes a TSQL statement against data source given enity framework context and returns strongly typed result.

You can find more information about ExcuteStoreQuery from following link.
http://msdn.microsoft.com/en-us/library/dd487208.aspx

Share:
Wednesday, April 4, 2012

Ternary operator in VB.NET

We all know about Ternary operator in C#.NET. I am a big fan of ternary operator and I like to use it instead of using IF..Else. Those who don’t know about ternary operator please go through below link.

http://msdn.microsoft.com/en-us/library/ty67wk28(v=vs.80).aspx

Here you can see ternary operator returns one of the two values based on the condition. See following example.
Share:

How to pad number with leading zero with C#

Recently I was working with a project where I was in need to format a number in such a way which can apply leading zero for particular format. So after doing such R and D I have found a great way to apply this leading zero format.

I was having need that I need to pad number in 5 digit format. So following is a table in which format I need my leading zero format.

1-> 00001
20->00020
300->00300
4000->04000
50000->5000

So in the above example you can see that 1 will become 00001 and 20 will become 00200 format so on. So to display an integer value in decimal format I have applied interger.Tostring(String) method where I have passed “Dn” as the value of the format parameter, where n represents the minimum length of the string. So if we pass 5 it will have padding up to 5 digits.
Share:
Tuesday, March 27, 2012

Important Mile stone achieved–I got 4,00,000 visitors for my blog

I have written this blog more than 5 years now and today I got one great news from sitemeter.com that I have achieved 4,00,000 visitors milestone. I would like to take this opportunity to thanks all the my readers for everything. I got nice appreciations from people around me and that’s encourage me to write more blogs.
Following is a screenshot of my blog statistics from sitemeter.com.
Share:
Saturday, February 4, 2012

Number- New HTML5 Input type

I have been writing few series of new HTML5 input types and this is another post on same series. In this post I am going to explain Number input types. The number type is for numeric values. When you use number input type it will have spinner with up and down arrow and with the help of this you can increase or decrease of value.

Attributes of Number Input type:

There are four attributes of Number input types.
  1. Value : This attribute is used to specify the default value of the input type once its first loaded. So what ever you put there in input value it will be there.
  2. Min: As name suggest it defines minimum value for a range that you can you can choose in number input types.
  3. Max: It defines maximum number value for the range a number input type can have.
  4. Step: This attribute defines the number which will decrease or increase number value. If you don’t specify the value for it the default value for this will be 1.
Share:

URL–New HTML5 input element

In earlier post we have seen how the email input tag work in the browser. HTML5 comes with lots of new goodies and today we are going to see one of another new html5 input types URL.

In most of the sites once you fill your contact and personal information it will ask for your URL. Till now there is no specific type for URL and we have to manually validate the URL with the Java Script but now with the HTML5 you don’t have do that. It will automatically validate the URL. For the browsers that are not supporting this will work as normal input text box.

So let’s take a simple example of URL input type. I am going to use same ASP.NET MVC project that I have used for the earlier post. So Here is the code for that.
Share:
Sunday, January 29, 2012

Email-New Html5 input element

In most of the websites we have contact forms and other forms where we have some standard inputs like Phone,Email and Website URL and those are widely used in any site and has specific features. Email is one of the most standard used input elements which are used in our forms. Till HTML 4.1 we have standard input type text and that’s for we were doing input validation with java script and other technologies. While we all know HTML5 is there and it’s contains lots of goodies, One of them is email input types.

Email input type comes with HTML5 as standard input type. It has all validation by default which are required for email input like we must have @ and . while we entered email input type.
Share:

My first video for code refactoring in visual studio 2010

I have been planning this since long but now Its happened. I have created a video for visual studio 2010 code refactoring features. I have made this video public. Following is a link for that.

http://www.youtube.com/watch?v=HvC63rE7tB4&feature=share

Here is the video..


Please see the video and let me know your feedback. I am not a trained professional in this but I have tried to create it. Hope fully I will master this technique in some time. Stay tuned for more. Till then Happy
programming.

Shout it

kick it on DotNetKicks.com
Share:
Sunday, January 8, 2012

string.format escape sequence in c#

Recently I was working on something and I need to put a curly bracket on the string with a string.format function but I was not aware how to to do it. So I did some search on internet and found how to give escape sequence in string.format. Suppose You need to put curly bracket then you have write two ‘{{‘ instead of { to put ‘{‘ and same way ‘}}’ to put ‘}’

Let’s take simple example. Following is a code where I am printing simple string with string.format and Response.Write.

using System;
using System.Web.UI;

namespace CallBack
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write( string.Format(@"{{ escape sequence for string format from {0}}}", "DotNetJalps"));
        }

    }
}


Now let’s run that example in browser and let’s see how it goes.


C#,Escape Sequence,String.format

That’s it. It’s very easy to use.Hope you liked it. Stay tuned for more..Happy Programming.

Shout it

kick it on DotNetKicks.com
Share:
Saturday, January 7, 2012

Difference between generic handler and http handler- ASP.NET

Generic handler:

As per MSDN Generic Handler is a default handler which will have @webhandler directive and has .ashx extension this generic handler is not having UI but it provides response when ever any request made to this handler.

HTTP Handler:

HTTP Handler is a process which runs and continue to server request and give response based on the request handling code. This handler does not have UI and need to configured in the web.config against extensions. One of the great example of Http Handler is page handler of ASP.NET which serves .aspx pages request.

Difference between generic handler and http handler:

Following is a main differences between http handler and generic handler.
  1. Generic handler has a handler which can be accessed by url with .ashx extension while http handler is required to be configured in web.config against extension in web.config.It does not have any extension
  2. Typical example of generic handler are creating thumbnails of images and for http handler page handler which serves .aspx extension request and give response.
Hope you liked it.Stay tuned for more..Till then happy programming.

Shout it

kick it on DotNetKicks.com
Share:

how to vertically middle align text in div-HTML tip

Recently in one of the project I have to vertical align text in div. so doing some internet search I have found there are no proper way to do it. So I thought it would be good do share this within my readers.

Here is the code do vertically align text in div.

<div style="width: 25%;border:solid 1px red;display: table;vertical-align: middle;float:left;height:100px;">
<div style="display: table-cell;vertical-align: middle;">this is a very long text this is a very long text this is a very long text this is a very long text this is a very long text this is a very long text </div>
</div>

Here in above code you can see that I have created two divs first one will serve container for other div and other div has the text which I want to align vertically in div. So in container div you can see I have given its style to display table and in child div which has the text I have given its display style to table-cell and given vertical-align property to middle. 

That’s it now when you run this in browser you can see text is vertically aligned.

HTML Tip,Div,Vertical Align

Hope you liked it..Stay tuned for more..Till then happy programming.

Shout it

kick it on DotNetKicks.com
Share:

ASP.NET Page Methods with Parameters

In earlier post I have written how we can use page methods to call server-side from the java script. In this post I am going to explain How we can pass parameters to page methods with java script.
So let’s take a simple example to see how we can pass parameters to the page methods. I am going to create a page method Hello World which takes name as parameter and return a string to greet user from that page method below is code for that.

using System;
using System.Web.Services;

namespace PageMethods
{
 public partial class Test : System.Web.UI.Page
 {
    [WebMethod]
    public static string HelloWorld(string name)
    {
        return string.Format("Hi {0}",name);
    }
 }
}

As you can see in following page method it’s returning string with greetings. So now our server-side code is completed. Now it’s time to write HTML and java script code for this. Following is code for java script.

<script type="text/javascript">
 function GreetingsFromServer() {
     var name = 'Jalpesh';
     PageMethods.HelloWorld(name,OnSuccess, OnError);
     return false;
 }
 function OnSuccess(response) {
     alert(response);
 }
 function OnError(error) {
     alert(error);
 }
</script>

As you can see in above code I have created a function called ‘GreetingsFromServer’ which called page method helloworld with passing name parameter. Other two functions are handlers for the page methods Onsucess will be called if page method is called successfully without error other wise it will call onError method and alert error message.

Now we are done with java script so its time to write HTML code. So let’s write a HTML code for this page.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="PageMethods.Test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title>Page Method with parameter demo</title>
</head>
<body>
 <form id="form1" runat="server">
 <div>
     <asp:ScriptManager runat="server" EnablePageMethods="true" EnablePartialRendering="true">
     </asp:ScriptManager>

     <asp:button ID="btnHelloWorld" runat="server" Text="Greet User" OnClientClick="return GreetingsFromServer();"/>
 </div>
 </form>
</body>
</html>

As you can see from above code I have enabled page methods true with script manager and then I have called JavaScript function “GreetingsFromServer” on button client click. So it’s now time to run this code in browser. Following is output as expected.

PageMethodWithParameter

That’s it. It’s very easy hope you liked it..Stay tuned for more…Happy programming

Shout it

kick it on DotNetKicks.com
Share:

2011 Recap and Greatest hits

2011 year has been ended before so its time to write the year recap blog post.First of all I like to wish my friends,reader and everybody a happy new year. This year was very exciting in some way for this blog. First thing was happened that I have moved from blogspot domain to my own domain http://www.dotnetjalps.com. I have written this in a blog post why I was moving from blogspot to my personal domain. Another great thing was happened that I was awarded as MIcrosoft most valuable professional for visual C# for year 2011 it was great to be part of MVP communities and meet fellow Mvps.Professionally this year was good year as I have got chance work on the new technologies like Juqery Mobile,ASP.NET MVC and ASP.NET 4.0 on real time projects.

Events I have attended during year 2011

Professionally I was very busy with this year but still I managed to attend few events personally while I have attended lots of events and webcasts during this Year. I have attended two events this year one was Tech On Road 2011 at Ahmedabad and other was Windows Azure camp both event was great and followings are details blog post about it.

http://www.dotnetjalps.com/2011/06/tech-ed-on-road-2011-ahmedabada-great.html

http://www.dotnetjalps.com/2011/05/windows-azure-camp-at-ahmedabad.html

Greatest Hit for 2011

I have written 95 blog posts through year through I was really busy with professional environments but following are greatest hits as per blogger stats.
Sending email through System.Net.Mail.Smtpmail in asp.net 3.5/2.0
How to take ScreenShot in C#
Enumeration in C#.NET,VB.NET
How to call a web service from JavaScript with asp.net Ajax
That’s it. Once again thank you for reading this blog and Happy new year to all of you. Stay tuned for more I am planning to write more and more blog post this year. Till then happy programming.

Shout it

kick it on DotNetKicks.com
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews