by Edward
04 June 2012 09:24

To follow on from my post on the latest version of Visual Studio 11, now officially launching as Visual Studio 2012 that is coming later this year. Microsoft is still aiming for a 4th quarter of 2012 release, to go with the release of .Net Framework 4.5 and Windows 8. Here is some more details on the updated version of Visual Studio 2012.
A few highlights:
- One thing I was not font of in the Beta release, was the dull grey theme. It now looks like the Visual Studio guys decided to enable themes and you can now brighten the background and make the status bar change color depending on your status. You can either choose the Light or Dark color theme for the Visual Studio UI. For more information, see Microsoft MSDM How to: Change the Fonts and Colors Used in the IDE.
- You can also search across the IDE for a specific word, phrase and choose from the dialog box or window what is associated with the item.
- Use features of ECMAScript 5 and the HTLM5 DOM.
- Provide IntelliSense for function overloads and variables.
- Create UML class diagrams from existing code.
- Run, monitor, and manage builds by using an enhanced interface.
- Debug your build process more easily.
- More integration with Sharepoint. For example creating lists and content types by using designers
What versions will be available for Visual Studio 2012:Visual Studio Ultimate 2012
- Visual Studio Premium 2012
- Visual Studio Professional 2012
- Visual Studio Test Professional 2012
- Visual Studio Team Foundation Server 2012
More details can be found on the Visual Studio 2012 RC webpage
by Edward
30 May 2012 20:25
On 6 June 2012 it will be World IPv6 Day. On this day the IPv6 (Internet Protocol version 6) will be switched on and co-exist with IPv4.
What is IPv6:
From wiki
"IPv6 (Internet Protocol version 6) is a version of the Internet Protocol (IP) intended to succeed IPv4, which is the protocol currently used to direct almost all Internet traffic.[1]
The Internet operates by transferring data between hosts in packets that are routed across networks as specified by routing protocols. These packets require an addressing scheme, such as IPv4 or IPv6, to specify their source and destination addresses."
The main advantage of IPv6 over IPv4 is its larger address space. The length of an IPv6 address is 128 bits, compared to 32 bits in IPv4.
What does IPPv6 look like:
IPv4 IP addresses consists of four bytes (32 bits) and this is written in dotted decimal as 10.0.0.1
An IPv6 address is represented by 8 groups of 16-bit hexadecimal values separated by colons ":"
2001:0db8:85a3:0000:0000:8a2e:0370:7334
2607:f0d0:1002:0051:0000:0000:0000:0004
All IPv6 addresses are divided into two parts:
- a 64-bit network prefix, and
- a 64-bit interface identifier.
Another interesting fact is that the hexadecimal digits are case-insensitive.
by Edward
10 December 2011 09:31
There is a new version of Visual Studio coming in 2012, and codenamed "Visual Studio 11". The final branding/name has not been confirmed, and will probably only be confirmed once the final product is ready to be made available. Microsoft is aiming for a 4th quarter release, to go with the release of .Net Framework 4.5 and Windows 8.
Here are a few things to look forward too...
- Support for .Net framework 4.5
- Windows 8 support
- Build metro-style applications
- Support for asynchronous programming in C#
- Support for state machines in Windows Workflow
- More tooling for HTML5 and CSS 3 in ASP.Net.
- Includes templates to help developers in writing Metro-Style — meaning WinRT-based — applications with JavaScript, C#, VB and/or C++.
- Simplified Toolbar: eliminated the clutter and ensured that you only ever need one row of toolbars to get your job done
- Improved Solution Explorer: Allows you to search and browse the relationships of types and members within VB, C# and C++ projects.
- Added search capabilities to the Toolbox and Add Reference Dialog.
Silverlight 6 and Expression Studio 6 will follow after the release of Visual Studio 11, probably in the beginning of 2013.
Update 1 March 2012:
Visual Studio 11 Beta has been released. Below are a few links on the release.
http://www.microsoft.com/presspass/features/2012/feb12/02-23VisualStudioBetaPreview.mspx
http://msdn.microsoft.com/en-us/library/hh156499%28v=vs.110%29.aspx
http://visualstudiomagazine.com/articles/2012/02/29/chart-visual-studio-11-vs-vs-10-vs-common-project-types.aspx
by Edward
15 November 2011 19:09
I recently wanted to get hashtags from a string and convert this to a clickable link (think Twitter integration). There are several ways of doing this, but I wanted to use regex. I find using regex easier to use when manipulating string values, then say using a for loop to check for the hash for each word in a string. If you want to use the loop method, you will need to split the string and then loop through each word and then check for a hashtag at the beginning of the word, and then make it clickable using an ahref tag. You would possibly also have to encode '#' with '%23' to parse the string and display on the webpage.
Below is a small function that will take the input and replace a hashtag with a clickable link.
Code Sample:
public static string GetHashTag(string urlText)
{
Regex urlregex = new Regex(@"(#)((?:[A-Za-z0-9-_]*))", RegexOptions.IgnoreCase
| RegexOptions.Compiled);
return urlregex.Replace(urlText, "<a href=\"$1$2\" style=\"color: #f68b1f;\">$1$2</a>");
}
by Edward
20 July 2011 19:40
Cache.Add
Calling the Add method returns an object that represents the cached item. If the key already exists in the Cache the method will fail.
Cache.Insert
Calling the Insert method does not return an object. If the key already exists in the Cache it will overwrite the copy in the Cache.
object instance = (object) Cache["thekey"];
if (instance == null)
{
instance = GetNewValueAndInsert(); // Get new data to insert into the cache
Cache.Insert(key, instance, ...);
}
return instance;
It is important to know that only one instance of the Cache class is created per application domain, and it remains valid as long as the application domain remains active.
For more information, read the following MSDN article.
by Edward
19 May 2011 18:32
It is always a good idea to try and validate any user input, before the page is submitted or a request is made to the database. This will cut down on unnecessary "back and forth" trips to the database, and also save on performance or showing nasty error pages, if you are not handling exceptions correctly.
To validate any user input, you can use the RegularExpressionValidator control provided with the .Net framework. If you need to validate other forms of input, such as query strings, cookies, or HTML input, you can use the System.Text.RegularExpressions.Regex class.
Here is small code snippet which will accept any numeric/decimal digits (e.g. 100.05), but not any alpha-numeric (e.g. £100.05). You must also have at least one digit before and one after the decimal place. It validates for a positive or negative currency amount. If there is a decimal point, it requires 2 numeric characters after the decimal point to be valid.
<asp:TextBox ID="txtAmount" runat="server" />
<asp:Button ID="btnSaveDetails" runat="server" Text="Submit" OnClick="btnSaveDetails_Click" />
<asp:RegularExpressionValidator ID="rvDecimal" ControlToValidate="txtAmount" runat="server"
ErrorMessage="Please enter a valid amount." ValidationExpression="^(-)?\d+(\.\d\d)?$">
</asp:RegularExpressionValidator>
by Edward
25 April 2011 07:44
Here is a list of server environment variables that can be accessed by using ASP.NET. These variables can tell us important details on the server environment in which the page is running or more information about visitors to the page.
| Variable | Description |
| ALL_HTTP |
Returns all HTTP headers sent by the client. Always prefixed with HTTP_ and capitalized |
| ALL_RAW |
Returns all headers in raw form |
| APPL_MD_PATH |
Returns the meta base path for the application for the ISAPI DLL |
| APPL_PHYSICAL_PATH |
Returns the physical path corresponding to the meta base path |
| AUTH_PASSWORD |
Returns the value entered in the client's authentication dialog |
| AUTH_TYPE |
The authentication method that the server uses to validate users |
| AUTH_USER |
Returns the raw authenticated user name |
| CERT_COOKIE |
Returns the unique ID for client certificate as a string |
| CERT_FLAGS |
bit0 is set to 1 if the client certificate is present and bit1 is set to 1 if the cCertification authority of the client certificate is not valid |
| CERT_ISSUER |
Returns the issuer field of the client certificate |
| CERT_KEYSIZE |
Returns the number of bits in Secure Sockets Layer connection key size |
| CERT_SECRETKEYSIZE |
Returns the number of bits in server certificate private key |
| CERT_SERIALNUMBER |
Returns the serial number field of the client certificate |
| CERT_SERVER_ISSUER |
Returns the issuer field of the server certificate |
| CERT_SERVER_SUBJECT |
Returns the subject field of the server certificate |
| CERT_SUBJECT |
Returns the subject field of the client certificate |
| CONTENT_LENGTH |
Returns the length of the content as sent by the client |
| CONTENT_TYPE |
Returns the data type of the content |
| GATEWAY_INTERFACE |
Returns the revision of the CGI specification used by the server |
| HTTP_<HeaderName> |
Returns the value stored in the header HeaderName |
| HTTP_ACCEPT |
Returns the value of the Accept header |
| HTTP_ACCEPT_LANGUAGE |
Returns a string describing the language to use for displaying content |
| HTTP_COOKIE |
Returns the cookie string included with the request |
| HTTP_REFERER |
Returns a string containing the URL of the page that referred the request to the current page using an <a> tag. If the page is redirected, HTTP_REFERER is empty |
| HTTP_USER_AGENT |
Returns a string describing the browser that sent the request |
| HTTPS |
Returns ON if the request came in through secure channel or OFF if the request came in through a non-secure channel |
| HTTPS_KEYSIZE |
Returns the number of bits in Secure Sockets Layer connection key size |
| HTTPS_SECRETKEYSIZE |
Returns the number of bits in server certificate private key |
| HTTPS_SERVER_ISSUER |
Returns the issuer field of the server certificate |
| HTTPS_SERVER_SUBJECT |
Returns the subject field of the server certificate |
| INSTANCE_ID |
The ID for the IIS instance in text format |
| INSTANCE_META_PATH |
The meta base path for the instance of IIS that responds to the request |
| LOCAL_ADDR |
Returns the server address on which the request came in |
| LOGON_USER |
Returns the Windows account that the user is logged into |
| PATH_INFO |
Returns extra path information as given by the client |
| PATH_TRANSLATED |
A translated version of PATH_INFO that takes the path and performs any necessary virtual-to-physical mapping |
| QUERY_STRING |
Returns the query information stored in the string following the question mark (?) in the HTTP request |
| REMOTE_ADDR |
Returns the IP address of the remote host making the request |
| REMOTE_HOST |
Returns the name of the host making the request |
| REMOTE_USER |
Returns an unmapped user-name string sent in by the user |
| REQUEST_METHOD |
Returns the method used to make the request |
| SCRIPT_NAME |
Returns a virtual path to the script being executed |
| SERVER_NAME |
Returns the server's host name, DNS alias, or IP address as it would appear in self-referencing URLs |
| SERVER_PORT |
Returns the port number to which the request was sent |
| SERVER_PORT_SECURE |
Returns a string that contains 0 or 1. If the request is being handled on the secure port, it will be 1. Otherwise, it will be 0 |
| SERVER_PROTOCOL |
Returns the name and revision of the request information protocol |
| SERVER_SOFTWARE |
Returns the name and version of the server software that answers the request and runs the gateway |
| URL |
Returns the base portion of the URL |
by Edward
26 March 2011 17:19
A simple but unknown to many developers is the two methods for padding available in the String class. Using these two methods you can add padding to the left or to the right of a string to achieve a desired length. A real world example will be to add a '0' to a string value when a area code must be a specific length.
The two methods for this example is as follows:
String.PadLeft : Right aligns and pads a string from the left.
String.PadRight : Left aligns and pads a string from the right.
The following example shows how to indent strings using method for padding:
PadLeft:
string originalString = "123";
Console.WriteLine(originalString.PadLeft(3, '0'));
PadRight:
string originalString = "123";
Console.WriteLine(originalString.PadRight(3, '0'));
You should also understand that this does not format the original value, for example formatting a integer to decimal, but just 'append' a character either on the left or the right of the string.
by Edward
19 February 2011 17:15
I was recently working on a project where it was important to display the version number of the code on the page for testing purposes as well as making sure the correct set of code goes to production. If you don't use a build server, or just copy your code over to your hosting space, then the following might be of help. By using reflection you can get the major, minor, build, and revision numbers of the assembly and the display it on your web page, or use however you need too.
The following code sample will help you with getting the version number of your application.
private static void Main(string[] args)
{
//Get Application version details
ApplicationDetails applicationDetails = new ApplicationDetails();
string versionNumber = applicationDetails.GetVersion();
}
class ApplicationDetails
{
/// <summary>
/// Gets the version.
/// </summary>
public string GetVersion()
{
return GetType().Assembly.GetName().Version.ToString();
}
}
You can set the version number to auto increment, by setting it in the properties window of your application.

by Edward
10 January 2011 19:56
At the end of last year(December 2010), Microsoft released a service pack for Visual Studio 2010. The service pack is still in BETA mode, and therefore must be treated as any BETA software.... handle with care!
I was happy to hear there was a new service pack on it's way, which has some bug fixes and includes fixes for the text editor when coding javascript, css, and html. One bug I wanted to see fixed was the 'crash bug' where my editor seems to crash unexpectantly when working with older versions of the .net framework. Since the install I have not had any crashes, although I must state that I have not been working a lot over the December/January period!
Other key updates to look out for, is that VS2010 SP1 BETA allows the debugger to support IIS Express. The IntelliTrace now also supports Workflows and projects that use Web Parts. There's also support for unit testing targeting .Net 3.5, and support for Visual C++, Visual Basic, SQL Server Compact 4.0 Design-Time, with enhancements for web deployment.
If you want to download SP1 BETA, you can find the download page here, but like I said - make sure you know the risks of installing BETA software!