Sunday, April 21, 2013

Server.MapPath variations

Those are working on in web technologies like ASP.Net and ASP are already familiar with server.MapPath method.  It is used to Maps a virtual or relative path to a physical path. Recently I had discussion with my friends what kind of options we have for Server.MapPath and We have discussed lots of things. So I thought it will be a good idea to write a blog post about it. I know this is very basic but sometimes we were not aware about basic things. So following are different kind of options we have with Server.MapPath.
  • Server.MapPath("~") return the root physical path of application.
  • Server.MapPath(“.”) returns the current physical path of a executing file(i.e .aspx file)
  • Server.MapPath(“..”) returns the current physical path of parent directory of executing file.
  • Server.MapPath("/") returns the he physical path to the root of the domain name
It’s very basic so if you try first one. It will load c:\users\lenovo\documents\visual studio 11\Projects\WebApplication1\WebApplication1\

It’s very easy hope you like it. Stay tuned for more.
Share:
Thursday, April 11, 2013

Two free spell checker extension for visual studio 2012 every developer should use

We all are humans and we tends to make mistakes. I am personally take care about lots of spelling mistakes when writing code but sometimes we don’t identify whether there is a spelling mistake there or not. At that time this spell checker extensions come handy.There are plenty of options available for spell checker extensions but In this post I am going to explain those two free spell checker plugins that I am using.

Spell Checker by Noah Richards:


This is a excellent plugin for identifying the spelling mistakes. You can download plugin from following url.

http://visualstudiogallery.msdn.microsoft.com/7c8341f1-ebac-40c8-92c2-476db8d523ce

It’s provides spelling checks for almost all the files.
  1. Plain text files where entire file will be checked for incorrect spelling.
  2. Source code(.cs files)
  3. HTML/ASP files.
For each spelling error, the user is presented with a list of alternative spellings, via a smart tag (activate with ctrl+.), and the option to ignore the word or add it to the user's dictionary.

You can configure the color of the squiggle under misspelled words by changing the foreground color of Spelling Error (in Tools->Options->Environment->Fonts and Colors).  The default color is red. Following is a example for that.

SpellChecker
Share:
Wednesday, April 10, 2013

Why sometimes it’s not a good idea to use session variables in class library project.

As we all know web pages are stateless pages and we need to use session variables in web application to maintain some session over page. Some time we divide our application into multiple layers for example business logic layer,database layer etc. This all layers will be a class library projects.

So when you have your applications divided into the multiple layers at that time you might need to use session variables in the class library projects. For that we are adding System.Web namespace as a reference to a class library project and then we can use session with HttpContext object. That’s works fine if your layers are going to be used in web application projects. But for example if you have service oriented architecture and your services also access your class libraries via non standard protocol i.e. WCF Service hosted on TCP/IP bindings. At that time sessions will not work.

Instead of that you should always use the parameters in method and avoid direct use of session variables. That parameters will passed either from the web application or from the services which is calling the class libraries.

Hope you liked it. Stay tuned for more..
Share:

My feed url changed

Before one year my blog has its own domain name www.dotnetjalps.com and at that time I did not changed the URL of my rss feeds. But now feed burner is providing me a way to change it without effecting my current subscribers so I have changed that to match my domain name.

Following is a new URL for my feeds.
http://feeds.feedburner.com/DotNetJalps

Please note that existing subscribers don’t have to change anything. Only the new subscribers will have that changed now.

Share:
Monday, March 25, 2013

ASP.NET 4.5 TextBox TextMode Property

Right now everybody is talking about HTML5 and its contains lots of new features like web sockets, canvas, new intput types with validation etc.

ASP.NET 4.5 text mode property enhancement:


With HTML5 new input types is going to be one of coolest feature and in future more and more people are going to use that feature. So in asp.net 4.5 asp.net development team given a support via TextMode property enhancements.

In earlier versions of ASP.NET we used have only three properties for TextMode property of asp.net textbox control.
  1. MultiLine- for multiline textbox.
  2. Password- for password textbox
  3. SignleLine –for single line textbox
With ASP.NET 4.5 you are going to have tons of options with TextMode property.
  1. Color- for Color entries
  2. Date-  for date entries. You can enter dates only
  3. DateTime – for datetime entries with respect to local time zone.
  4. DateTimeLocal- for datetime entries with respect to local time zone.
  5. Email- for email address
  6. Month- for month and year entry.
  7. Number- for  entering numeric values.
  8. Range- for containing range between two numbers.
  9. Search- for search field. A search field is like regular text fields
  10. Tel- for telephone number.
  11. Url- for website url entries. It will only contain urls.
  12. Week- for entering weeks and year.
Share:
Saturday, March 23, 2013

Difference between All and Any operator in linq

In this post we are going to learn about difference between ‘All’ and ‘Any’ operator in Linq.

Difference between ‘All’ and ‘Any’ operator:


All operator checks whether all elements have met specific conditions or not while Any operator check whether there is any elements exist in collection or not?

So what we are waiting for Let’s take a example.
using System;
using System.Linq;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = {1,2,3,4,5};
            bool result = intArray.All(i => i > 2);
            Console.WriteLine(result);
            result = intArray.Any();
            Console.WriteLine(result);
            Console.ReadLine();
        }
    }
}
In the above example you can see that I have created an integer array and then checked with both all and any operator. In first condition I have checked that whether elements are greater then 2 or not and same way I have checked with any operator that its contains any element or not?

Now let’s run that example. To see how its works.
Share:
Friday, March 22, 2013

My blog post appears on asp.net community spot light

Once again my blog post about CRUD operations with asp.net and petapoco appears on the Microsoft asp.net official website. I would like to thank you all for specially Jon Galloway and asp.net team.

ASPnet

A big thank you for every one for supporting me.
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