Jack @ ASP.NET

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries for the ‘Visual Studio’ Category

Visual Stusio 2010: Quickly Closing Documents

Before (VS 2008)

image

After (VS 2010)

image

The majority of feedback around this change was positive, but, as with most UI changes, there has been a vocal group that preferred the older placement.  When asked what they liked about the old placement, 99% of the time the response was, “I liked the ability to quickly close tabs by repeatedly clicking on the ‘X’ without moving my mouse.” 

I’ll admit it: I used that feature quite a bit to quickly close tabs.  That is, until I found out that there are better and more efficient ways to clean up the Tab Well.  Once I discovered these, I never looked back.  So, for this “Tips and Tricks” article, I wanted to share some of those ways to quickly close documents. 

 

image#1: Window->Close All Documents

Under the Window menu is a handy command: Close All Documents.  Clicking this will prompt you to save your work and will then close all documents that are currently open.  Yes, this does affect more than just the documents in the Tab Well – floating documents are also closed.  If you don’t want to take your hands off the keyboard, simply press Alt+ W, L, to invoke the command (You can also assign it a keyboard shortcut under Tools->Options->Environment->Keyboard).

 #2: Ctrl+F4

Another handy shortcut is Ctrl+F4 which, on most machines, is bound to the command Window.CloseDocumentWindow.  Pressing this keyboard combination will close the current document window that has focus.  Therefore, if you want to quickly get rid of a number of items in your tab well, just keep pressing Ctrl+F4 and eventually they’ll be gone. 

#3: Right-Click->Close All But This

If you want to close all but one open file, simply right-click on the tab and select Close All But This.  This will close all open documents (floating included) except the tab you’ve right-clicked on. 

#4: Middle Click

For those that prefer to use the mouse instead of the keyboard, there’s still a quick way to close tabs: the middle click.  This shortcut actually works in a number of other applicatios as well.  Simply place your mouse on the tab well and middle click to close the tab.  You can keep your mouse in the first spot and click away.

Issue with Auto-Generated Designer Files not Adding Controls: Hotfix available

A hotfix is now available for issues most commonly described as "Controls are not being recognized in the code-behind" and "Editing existing .aspx regenerates .aspx.designer.(cs), but most of the controls are now missing”.

This hotfix can be downloaded from: http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=27117

The update addresses the following Connect bugs:

    * Cannot embed standard asp.net controls in Ajax Control Toolkit TabContainer
    * Controls in CreateUserWizard WizardStep not visible as before
    * issue with auto-generated Designer files not addding components
    * Code Generation in 2010 RC doesn’t work the same as 2008 for ASP.NET Application
    * Editing existing .aspx regenerates designer.cs (good) but most of the controls are now missing (bad)
    * ASP.NET designer fails to auto-generate fields
    * Bug in generating the designer.cs file in VS2010 (Converting VS2008 project to VS2010)

Polyglot Programming Languages in .NET

A polyglot is a computer program or script written in a valid form of multiple programming languages, which performs the same operations or output independently of the programming language used to compile or interpret it.

Generally polyglots are written in a combination of C (which allows redefinition of tokens with a preprocessor) and a scripting programming language such as Lisp, Perl or sh.

For the past few years, many industry leaders were saying that developers needed to know multiple languages. They were right, because learning multiple languages (if done correctly) meant that you needed to learn different programming idioms: procedural programming, object oriented programming, functional programming, and so on.

But that’s painful. Why should I need to learn new syntax to use new idioms? Curly braces aren’t allowed in FP? semicolons aren’t permitted in dynamic languages?

Instead, why can’t a general purpose programming language support multiple programming idioms? C#, VB.NET, and C++ are starting to seriously support that. (Other languages may be doing this as well; I don’t know). All these languages have added (or are adding) lambda expressions which support functional programming concepts. (C++ has used Class Type Functors for this purpose for some time). C# is adding support for dynamic typing (as is VB.NET, in a more strict fashion than previously supported). Implicit typing is supported in C#, C++, and VB.NET as well.

This trend will continue as more and more developers want to use the best programming idiom for a particular task without learning a totally different syntax. Any programming language that calls itself a “general purpose language” will support multiple idioms.

Add New Iterations in TFS

Do you know how to add new iterations in TFS, than, when add new work items, we can select the newly created iterations.

image

Required Permissions

To perform this procedure, you must be a member of the Project Administrators security group for the team project. You cannot explicitly set the necessary security permissions for this procedure. For more information, see Team Foundation Server Permissions.

To modify the team project iterationsTFS_New_Iteration
  1. On the Team menu, point to Team Project Settings, and then click Areas and Iterations.

  2. On the Areas and Iterations dialog box, click the Iterations tab.

  3. Use the toolbar buttons to change the current iteration:

    • Click Add a child node to add a new node under the currently selected node.

    • Click Delete node to delete the currently selected node. In the Delete Nodes dialog box, select the new path for the items to reference, and then click OK.

    • Click Move a node up amongst its siblings to promote the currently selected node higher in the tree.

    • Click Move a node down amongst its siblings to demote the currently selected node lower in the tree.

    • Click Make the selected node a child of its preceding sibling to make the currently selected node a child of the node immediately above it.

    • Click Make the selected node a sibling of its parent to make the currently selected node a peer of the node immediately above it.

  4. Click Close.

 

At last, pay attentions, the name of an iteration node cannot:

  • Contain more than 255 characters.

  • Contain Unicode control characters.

  • Contain any one of the following characters: \ / $ ? * : " & > < # % |

  • Be a system reserve name such as prn, com1, com2, com3, com4, com5, com6, com7, com8, com9, com10, lpt1, lpt2, lpt3, lpt4, lpt5, lpt6, lpt7, lpt8, lpt9, nul, con, aux.

  • Be one of the following characters: “.” or “..

  • Be characters considered invalid by the local file system. For example, Windows-based desktop operating systems might consider the following characters to be invalid if used in the path name: ASCII/Unicode characters 1 through 31, quotation mark ("), less than (<), greater than (>), pipe (|), backspace (\b), null (\0) and tab (\t).

  • Have a total path length greater than 4000 characters.

  • Have a total hierarchy depth of more than 14 levels.

List(T).BinarySearch in C#

I think most of us are quite familiar with binary search. Binary search is an algorithm for locating the position of an element in a sorted list by checking the middle, eliminating half of the list from consideration, and then performing the search on the remaining half.If the middle element is equal to the sought value, then the position has been found; otherwise, the upper half or lower half is chosen for search based on whether the element is greater than or less than the middle element. The method reduces the number of elements needed to be checked by a factor of two each time, and finds the target value, if it exists in logarithmic time. A binary search is a dichotomy divide and conquer search algorithm.

In C#, .Net provide a List<T>.BinarySearch Method (T) which can be used easily. here is a demo:

   1: // Init a long type list

   2: var myList = new List<long>();

   3: foreach (var item in "269, 361, 347, 355, 352, 346, 351, 354".Split(','))

   4: {

   5:     myList.Add(long.Parse(item.Trim()));

   6: }

   7:  

   8: // sort

   9: myList.Sort();

  10: var ret = myList.BinarySearch(347);

  11: Console.WriteLine(ret);

Note, I have a ‘myList.Sort();’ before call the BinarySearch, why? It is because BinarySearch will Search the entire sorted System.Collections.Generic.List<T> for an element using the default comparer and returns the zero-based index of the element.

Yes, it is sorted list that binary search will operate on! So remember make your list sorted before call binary search function

Top 10 Favorite Visual Studio Shortcuts

Use shortcuts can increase your development speed and save you lots of times. These are some of my favorite and most used shortcuts in visual studio, I only list 10 of them, hope it is useful.

  1. Holding down the Ctrl key -  while the completion list is displayed makes the list partially transparent.

  2. Ctrl + – and the opposite Ctrl + Shift + -  To move the cursor back or forward to the last position without having to scroll or switch  files.

  3. Shift+Alt+Enter Switches to Full Screen Mode

  4. Ctrl+K, Ctrl+C Comment a block,   Ctrl+K, Ctrl+U Uncomment the block

  5. Shift + Alt + F10 then Enter expands the smart tag to insert a using statement or implement an Interface

  6. Ctrl+K, Ctrl+D Auto format the file (Source, xml or  html)

  7. Ctrl+M, Ctrl+M – Toggle Outlining Expansion—Based on the current cursor position in the editor window, hides or unhides the outline region.

  8. Ctrl+M, Ctrl+ O Collapses all outlining to  definition and then Ctrl+M, Ctrl+M to toggle the current block to expanded or collapsed.

  9. Shift+ F12, Finds a reference to the selected item or the item under the cursor

  10. Ctrl-Shift-F12, Moves to the next task in the TaskList window