Tuesday, June 15, 2010

Code Snippets in Visual Studio 2008/2010

Another cool feature of Microsoft Visual Studio 2008/2010. Code snippets are pieces of codes that are pre-set in snippets files and has a shortcut associated with it. This feature can save you a lot of time coding.
we all build our "for" statements and "if" statements and all kind of code parts that we code repeatedly almost everyday.
VS comes with many snippets preloaded but you can add your own if you have a specific code snippets specific to you that you want to add to the library.

Here is how it looks when you start typing the shortcuts. The code snippets has their own icon (Click the Image to enlarge)::




Once you choose your snippet than click the "tab" button twice and the code will populate:





In order to see all the available snippets or add your own go to "tools" -> "Code Snippets Manager"

Click the Image to enlarge



And you will see this screen (Click the Image to enlarge):

Click the Image to enlarge



To create a code snippet of your own you will need to build the file in a n XML format and supply it with all the attributes (shortcut, code etc.).


Here is how the above "for" statement snippet file looks like (Click the Image to enlarge)::

Click the Image to enlarge

Monday, June 14, 2010

ToDo List - an .NET 3.5 MVC2 project utilizing Entity framework & MS-SQL

Well, Since my web hosting does not support MVC2 framework at the moment I can't give you a full demonstration but I Can show you some of the neat, cool stuff Microsoft added to the .NET 3.5 framework.

Motivation
The MVC is Microsoft's implementation of the MVC design pattern (Model–View–Controller) (Click the link in order to learn more about the design pattern). With the increasing importance of a strong web presence for today's business world and the constant change and evolution of the search engines (Google, Bing, Yahoo, etc.) there are new development requirements that didn't exist before.
The business' SEO (Search Engine Optimization) activities added new technical development requirement. If until now nobody cared how our URL addresses looked like or what keywords they contained, it has changes dramatically in the last year or so. Search engines these days look at the folder names, the page name and the suffixes as input for the ranking algorithms.
I do not wish to open a SEO debate here (I might add a post about it to my Blog soon), I want to show you a new EASY way to make your web application's URLs a lot more SE friendly and user friendly at the same time.



Technology
I used Visual Studio 2008 over .NET framework 3.5 and MS-SQL Server 2008
The new features introduced in this project are: ASP.NET MVC2.0 & ADO.NET Entity Framework . Combined together these new features of .NET 3.5 are very powerful and make the development of new, SEO friendly websites really simple.



The Main Idea
We have three main components:
•Model - the Data layer of our projects. Provide access to the data.
•Control - the Business layer, where we do all the business logic of our project and function as an intermediate between the Model (Data) layer and the View(UI) layer.
•View - a presentation layer, the UI (User Interface) layer. May contain some logic but only UI related logic (validations etc.).

Want to read more? Click Here

Tuesday, June 8, 2010

Super cool UNdocumented SQL procedure

xp_dirtree is an UNdocumented SQL procedure. you can use it to get a list of folders in a directory, including sub-folder to any depth!!!

EXEC master..xp_dirtree '[directory_path]', [depth]

for example:
EXEC master..xp_dirtree 'c:\Installs', 1
will get you a list of folders in the directory c:\Installs.

another example
EXEC master..xp_dirtree 'c:\Installs', 1
will get you a list of folders in the directory c:\Installs AND all the folders under these folders (2 levels down)

small query that can make your life easier sometimes.

Tuesday, June 1, 2010

Search & Replace values in MS-SQL 2005/20088 text fields

Starting from MS-SQL 2005 there is a new SQL function called "REPLACE" and you can use it to replace values in text fields (varchar/nvarchar/nchar...).

just put the right table names and the right column names in the following code:

update TableTable
set ArticleContent = (
SELECT REPLACE(TargetColumn, 'old value', 'new value')
FROM TargetTable Table_In
where Table_Outside.ArticleId = Table_In.ArticleId
)
from TargetTable Table_Outside