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:

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