Yanesh Tyagi writes …

August 10, 2008

VB.net to c# converter

Filed under: .Net, Programming, Technology — yaneshtyagi @ 9:58 am
Tags: , ,

Many times we need to convert VB.net code to c#. There are many utilities to do this. but none of these is perfect as these have one or other shortcomings. Most of these utilities are the windows apps written in c# language. The draw back of windows app is that you need to upgrade the app at times.

I was looking for an online app for the conversion. And after some googling I found a cool online tool from the Developer Fusion Lab. This conversion tool is quite accurate in conversion and if it could not convert any code then it inserts the error message into the code. So one can easily identify the error message and do the manual conversion.

Link:
Convert VB.NET to C# – A free code conversion tool from Developer Fusion

May 26, 2008

Automatic Formatting of Markup (HTML) in ASP.NET

Daniel at dimebrain did a really fantastic work writing a plug-in for VS that can format the markup in asp.net. When you build a web page using the VS designer, it auto generates the markup. But the auto generated code so clustered and impossibly hard to read.  You have to manually format the markup (HTML) code by hand. This is always very tiresome and boring job. Also this is wastage of time.

Daniel also felt the same. After being inspired by the Joe Stagner, he developed this plug-in. It provides an additional Edit menu item and hotkey (Ctrl+K, Ctrl+Z) to automatically line up attributes in a selection of text, or format the entire document if no text is selected. The meat of the add-in is a handful of regular expressions that parse tags (XAML, HTML, and ASP.NET directives) and a few IDE tools to line them up according to their indent level.

Download Links:

Screen Shots:

December 4, 2007

Effective Use of Visual Studio 2005 – Keyboard Shortcuts

Filed under: .Net, Programming — yaneshtyagi @ 11:18 am
Tags: , ,
As a hardcore developer I found that typing is easy to me then using mouse. Mouse is an obstacle. Taking hands off the keyboard is time consuning. It takes me out of comfort zone. I like to use keyboard where ever possible and efficient. Thanks to the developers of Visual studio 2005, they provided keyboard shortcuts to the most frequest tasks.
Though the use of named commands is always recommended instead of keyboard shortcuts. But I found that these key strokes are most common and no one reassign these to custome actions. Its safe to get used to these shortcuts.

Here is a list of my favourite shortcusts.

Tool Boxes And Windows
  • CTRL+ALT+L: View Solution Explorer. I use Auto Hide for all of my tool windows to maximize screen real estate. Whenever I need to open the Solution Explorer, it’s just a shortcut away.
  • CTRL+ALT+X: Toolbox Window
  • CTRL+ALT+O: Output Window
  • CTRL+\, E: Error List Window
  • CTRL+\, T: Task List Window
  • F7: Toggle between Designer and Source views.
  • CTRL+PgDn: Toggle between Design and Source View in HTML editor.
  • SHIFT+ALT+Enter: Toggle full screen mode. This is especially useful if you have a small monitor. Since I upgraded to dual 17? monitors, I no longer needed to use full screen mode.
  • CTRL+SHIFT+A: Add New Item Window
  • ALT+F+F: Recent Files List

Building, Running And Debugging

  • F10: Debug – Step over.
  • F5: debug – Start
  • F11: debug – Step into
  • SHIFT+F11: Debug – step out
  • CTRL+F10: Debug – run to cursor
  • F9: Toggle Breakpoint
  • CTRL+SHIF+B: Build Solution. Related shortcuts:
  • ALT+B, U: Build selected Project
  • ALT+B, R: Rebuild Solution

Code Window

  • CTRL+D or CTRL+/: Find combo
  • CTRL+M, O: Collapse to Definitions.
  • CTRL+M, M: Toggle Outline Expension. Collapsed will become expanded and expanded will become collapsed.
  • CTRL+K, CTRL+C: Comment block.
  • CTRL+K, CTRL-U: Uncomment selected block
  • CTRL+-: Go back to the previous location in the navigation history.
  • CTRL+SHIFT+-: Go to the next location in the navigation history.
  • CTRL++: Select from last mouse pointer position to current mouse pointer position.
  • CTRL+ALT+Down Arrow: Show dropdown of currently open files. Type the first few letters of the file you want to select.
  • CTRL+K, D: Format code.
  • CTRL+L: Delete entire line.
  • CTRL+G: Go to line number. This is useful when you are looking at an exception stack trace and want to go to the offending line number.
  • CTRL+K, X: Insert “surrounds with” code snippet.
  • CTRL+K, K: Toggle bookmark.
  • CTRL+K, N: Next bookmark.
  • CTRL+K, P: Previous bookmark.
  • CTRL+K, L: Clear bookmark.
    CTRL+K, I: Quick Info
  • F12: Go to definition of a variable, object, or function.
  • SHIFT+F12: Find all references of a function or variable.

November 29, 2007

Effective Use of Visual Studio 2005 – Named Commands

Filed under: .Net, Programming, Technology — yaneshtyagi @ 5:43 pm
Tags: , ,

Command Window: Ctrl+Alt+A

Named commands are used to access VS features from Command Window. Visual Studio 2005 provides full intellisense support in the command window. I experienced that using named commands is much faster than accessing these features with mouse.

Named commands allow you to access and use menu commands in the command window. To use named commands, simply type the name of menu. Press ‘.’ and VS will provide intellisense. Type the name of the menu option or select it from intellisense.

Example:

To access Find Results 1 window you have to

1. Click on the ‘View’ menu and then
2. Click on the ‘Find Results’ and
3. Finally choose ‘Find Results 1′.

Now if you want to use named commands,
1. Press Ctrl+Alt+A to activate command window.
2. Type View.findresults1. You don’t need to type full text. Intellisense provides yoy write text. Just press enter.

Some Examples of Named Copmmands:

  • Window.NewWindow: Open a new window on your code.
  • Tools.Options: Bring up Options dialog box.
  • Edit.ViewWhiteSpace: (Ctrl+R, Ctrl+W) Replace white spaces with a dot.
  • Convert tab to spaces: Ctrl+K, Ctrl+D
  • Window.ActivateDocumentWindow: Switch to document window.
  • Window.AutoHide: Hide command window. (Use Ctrl+Alt+A to show command window)
  • Window.AutoHideAll: Hide all windows except document windows. It will hide even pinned-up windows too.
  • Window.ShowEzMDIFileList: Show Easy MDI File List.
  • Window.Split: Split code window into two. Both windows show same files but you can scroll them independently. Issue same command to close splitting.
  • Window.Windows: Open ‘Windows’  window. More Info
  • Edit.ClearAll: Clear Command Window.

Named Command and Keyboard Shortcuts

Usually VS features can be accessed in two ways: using keyboard shortcusts or  using named commands. But using named commands is easier than using keyboard shortcuts:

  1. You need to learn keyboard shortcuts. But named commands are not required to learn, as they are based of the menu navigation which is most commanlyt used.
  2. Keyboard shortcuts are customizable. You (or anybody else) can change them. If you are working on some other machine, you may not have same keyboard shortcuts.
  3. There is no help (intellisense) provided for keyboard shortcuts.

Images:

1. Easy MDI File List

EzMdiFileList

2. Split code window
Untitled

November 28, 2007

Effective Use Of Visual Studio 2005 – Handling Open Documents

Filed under: .Net, Programming, Technology — yaneshtyagi @ 12:48 pm
Tags: , , ,
Visual Studio 2005 provides some excellent document management capabilities. Most of the we are not aware of these features. One of the feature is open document tab groups. Unlike VS 2003, it shows only as much tabs as fits in the window width. There is no scrolling. Instead, VS 2005 provides dropdown menu to select from all open documents. Inseated of selecting open documents, you can also do some other functions.
I am planning to write a series on useful-but-less-known features of VS 2005. This is second post in the series. (read first post)

In continuation to my previous post on managing open documents, here are some more tricks.

Right click on the open document tab group. A context menu will appear with following options:
  1. Save default.aspx.vb
  2. Close
  3. Close all but this
  4. Copy full path
  5. Open containing folder
  6. New horizontal tab group
  7. New vertical tab group

Save default.aspx.vb

Allows you to save currently selected document. Currently selected document is the one which is open in the window.
Close
Close currently selected document.
Close all but this
Close all open documents except the currently selected document.
Copy full path
Copy full path of the currently selected document to the clipboard.
Open containing folder
Open the folder that contains the currently selected document. The folder is opened in the windows explorer.

New horizontal tab group
Open another document window. The two windows are tiled horizontally. Both window will have document tab group. This is useful when you want to open on two group of documents simultaneously.

New vertical tab group

Same as above option. But this makes the windows tiles vertically instead of horizontally.

November 27, 2007

Effective Use of Visual Studio 2005 – Closing Selected Window

Filed under: .Net, Programming, Technology — yaneshtyagi @ 10:20 am
Tags: , , ,
To close open documents selectively:
1. Go to Window -> Windows.

2. This will show list of all open windows (not just those which you see on the tabs).

3. Select the windows you want to close. Use shift (or ctrl) key for multiple selection. You can also use ctrl+A to select all windows.

4. Click “Close window(s)” button to close selected windows.

I experienced that the speed of loading a project into visual studio is directly proportional to the number of open documents. Generally, we open the document as we need it. And then we don’t close it. Visual studio 2005 displays only a few number of documents on the tabs. Rest remains open but are hidden. You can click on the down arrow near the ‘X’ button of the document window to select the open document. To keep you project loading fast, always keep minimum number of open documents.

November 20, 2007

Visual Studio 2008 and .NET 3.5 Released

Filed under: .Net, Programming, Technology — yaneshtyagi @ 6:44 am
Tags: , , ,

Microsoft shipped Visual Studio 2008 and .NET 3.5 today. Here are some resources for VS 2008:

1. ScottGu’s weblog is the primary and authentic source of information।
२. Somasegar’s Weblog
3. Paul Andrew blogged about a downloadable poster of commonly used types and namespace in .NET 3.5 (in pdf format), which is worth checking out.
4. View ASP.NET 3.5-specific videos at Microsoft’s official asp.net website.
5. Brad Abrams wrote about Design Guidelines, Managed code and the .NET Framework 3.5 in his blog.
6. Here is a 31 minute video at Channel 9.
7. VS 2008 is not shipped with MSDN. You can Download MSDN Library for VS 2008 from here.
8. The details about VS 2008 express edition (free) are available here.

November 15, 2007

Putting ASP.net Application In Offline Mode Using app_offline.htm

Today, I was updating a stored procedure of SQL Server Express Edition 2005 within the Visual Studio 2005. At the same time, I tried to open a page of my application in internet browser using IIS (localhost). And I got the error stating:

‘The application is currently offline. Remove app_offline.htm file from applications root directory.

I never heard of app_offline.htm file before. As a habit I pressed ‘F5′ to refresh the page and it worked fine. ‘What the hell was this?’, I thought. I googled about the file in error message and learned some interesting facts. Here is what I found:

app_offlinne.htm

When ASP.Net found a file names app_offlinne.htm in the root of a web application directory, it shut-down the application, unload the application domain from the server, and stop processing any new incoming requests for that application. ASP.NET also then respond to all requests for dynamic pages in the application by sending back the content of the app_offline.htm file (for example: you might want to have a “site under construction” or “down for maintenance” message).

Visual Studio 2005 And app_offline.htm

SQL Server 2005 express edition does not support multiple processes. Only single process can access database at a time. So when a database is accessed through visual studio, ASP.net runtime cannot access the database. This will result into the internal server error.  To prevent this, VS 2005 places app_offline.htm file in the application’s root directory. The file contain above message. This causes ASP.net to put the application in offline mode. Please note the accessing database means opening any component of the database (I.e. table, view, stored procedure etc.) into the design window. When design window is closed, VS 2005 removes app_offline.htm file.

Using app_offline.htm As A Feature

You may use app_offline.htm feature to put your application in offline mope for any purpose. This provides a convenient way to take down your application while you are making big changes or copying in lots of new page functionality (and you want to avoid the annoying problem of people hitting and activating your site in the middle of a content update). It can also be a useful way to immediately unlock and unload a SQL Express or Access database whose .mdf or .mdb data files are residing in the /app_data directory.

You should keep an eye on a feature of IE6 called “Show Friendly Http Errors”.  This can be configured in the Tools->Internet Options->Advanced tab within IE, and is on by default with IE6.  When this is on, and a server returns a non HTTP-200 status code with less than 512 bytes of content, IE will not show the returned HTML and instead substitutes its own generic status code message (which personally I don’t think is super friendly <g>).

So if you use the app_offline.htm feature, you should make sure you have at least 512 bytes of content within it to make sure that your HTML (instead of IE’s friendly status message) shows up to your users.  If you don’t want to have a lot of text show-up on the page, one trick you can use is to just add an html client-side comment with some bogus content to push it over 512 bytes.

Once you remove the app_offline.htm file, the next request into the application will cause ASP.NET to load the application and app-domain again, and life will continue along as normal.

References:

  1. Andy Gray wrote an interesting story on how his application stops working and starts giving error 404 when he killed visual studio process.
  2. Phill Scott writes his experience about suddenly getting error 404 and finding the app_offline.htm file culprit.
  3. Chris Ullman, author of Beginning ASP.NET 2.0 also had similar experience.

Acknowledgement

I must thank ScottGu for providing useful details about this mysterious file. I could not found any official documentation from Microsoft about this. But ScottGu’s blog is as authentic as Microsoft’s documentation.

kick it on DotNetKicks.com

July 18, 2007

What does Visual Studio 2008 mean to me

Filed under: Programming — yaneshtyagi @ 4:23 pm
Tags: ,

I returned to blogging after a long period of time. I gave up posting blogs on this site because I thought its useless. There is no point in writing thoughts in your blog. Instead, I preferred to keep a diary. Yesterday, I completed one month of diary keeping. Today, I was reviewing what I have written in my diary. And to my surprise, there was nothing to hide. Everything I have written could have been written on my blog. So I returned to this blog.

Today I read a mail from Microsoft. It said that Microsoft is going to to launch Visual Studio 2008 in Feb. I interpret this that I have to learn new technologies, features etc. Until now, I haven’t explored all the features of Visual Studio 2005. Currently I am working on .Net framework 2.0. Microsoft has already launched .Net framework 3.5 with new features and Vista support. What it mean to me is lots of study again. I know that switching from .Net 1.1 to 2.0 steal so much of my family time. I am thankful to my wife and daughter to gave their time to my studies. And I afraid that its going to be repeated again.

Sometimes I thought that choosing Microsoft Technologies (or event Information Technology) as my career is the biggest mistake of my career. Would I be an accountant, there will be no work in the late hours, no study in the night. Life would be easier than. But I am not sure if I will be satisfied with that life style or not.

Anyways, time has passed now. There is no way to change career track in this phase. So let me press CTRL+TAB to switch to Visual Studio window. Good bye and sweet dreams…

Blog at WordPress.com.