Wednesday, December 1, 2010

Reading App Settings from the Web.Config

For a Web Service that needs to read information form the web.config file (in its own virtual directory), the following is all you need to read the information:

using System.Configuration;
String value = ConfigurationManager.AppSettings["Param_1"].ToString();

The web.config file would contains something like this:

For more information, go to the following links:

The following link show how to read the root web.config file instead of the one in the virtual directory:

Wednesday, August 25, 2010

Creating Fixed Spaced Fonts for .NET

How to create a fixed space (mono spaced) font for .NET:

Dim f as Font = new Font(FontFamily.GenericMonospace, 12)

Monday, June 14, 2010

Windows Phone 7 - The Haves and the Have-Nots

While Windows Phone 7 (WP7) sounds intriguing as a platform for iPhone-type applications, TechEd 2010 was very illuminating on the many things that this new platform does not include and why you will unlikely be able to migrate your existing Windows Mobile applications forward. Let me go through the laundry list of the have-nots:

  • No native code support. Silverlight 3.0 and XNA are the only ways to develop applications for WP7. If you are not developing games, then Silverlight is probably the path you will be forced to take.
  • No Database support. SQL Server Compact is not part of WP7. Nor will SQLite or any other 3rd party database engine run either. One TechEd session had the gall to suggest that we should all use collections of objects and Linq as a replacement for SQL Server Compact. Access to data is only available through Web Services and what the application can store in Silverlight’s Isolated Storage. No one would confirm or deny that database support would ever be added to WP7.
  • No Side Loading Applications. Except for development mode, applications can only be loaded to WP7 devices through the Microsoft Marketplace. It doesn’t matter if the app if for internal use in your organization or not. Also, it is not free to use the Microsoft Marketplace.
  • Application approval is required. Microsoft claims that it will not be a blackbox like Apple where you stick an app in and hope it comes out; however, they also said they there is a list of applications types that will not be allowed. VOIP was they only example provided.

  • No access to data on SD cards. Since Silverlight applications can only use isolated storage, there is no way for an application to access information on an SD card. While some devices may support an SD card, the additional memory will apparently be made available for isolated storage, but you can’t preload the content.
  • No File System support. Again only Isolated Storage is available to a Silverlight app.

  • No RAPI support. There will no interacting with a WP7 device via the desktop. Obviously there will be some synchronization with Outlook, but nothing the developer will have control of.

  • Applications must be Silverlight 3. Silverlight 4 will not be available for WP7.

  • Out of Browser Silverlight support only. Silverlight is not going to be supported in browser on the phone.

  • Default Browser must be Internet Explorer. While Microsoft claimed that other browsers will be allowed on the phone, they can’t be the default. This is probably okay as long as the new Internet Explorer is better than the Windows Mobile version; however, is it possible to write a viable browser in Silverlight or XNA?

  • No Bluetooth API. While there is going to be Bluetooth support on the phone, there is no Bluetooth API.

  • No inter-process communications (IPC) and no Socket support.

  • No Video Capture Support. Phones will have a camera but not video capture support, and also no video brush.

  • No Outside TrueType Fonts - Microsoft experts claimed that you will not be able to use TrueType fonts other than the ones delivered with the device. This limitation makes since, how would you get them on the device. While there is supposed to be support for embedding TrueType fonts in your xap file in Silverlight 4, this will not be the version used on the device.
  • The TechEd demos of WP7 applications had a common theme; they crashed, hung up, or gave peculiar error messages. For a platform that is going to be delivered in the October timeframe (3 months away), it is hard to have much short-term faith in the new platform.

On the positive side, the list is not quite as long:
  • The Silverlight apps running on the phones looked good even if they were only Silverlight 3.
  • Lots of different soft input panels (SIPs) provided like numeric, URL, email, etc.
  • Built-in support and APIs for multi-touch, accelerometers, vibrator, microphone, and camera.

  • Phones are not going to be feature locked like Windows Mobiles. They should be upgradable like the iPhone.
  • Applications on the phones do not have the strange isolated storage limits that desktop Silverlight applications have.

Microsoft continually offered up that they were so rushed to get this phone to market that they had to leave a lot of things out. Since the phones are not feature locked (so they claim), maybe there will be a quick release cycle of new versions to fill in the missing components. If you are not planning on developing iPhone type applications (casual games or casual apps usually requiring a connection to a backend), you may be stuck waiting for a new release will new features (or jumping ship to Android or the iPhone). The WP7 platform as it is depicted today will not be able to support the sophisticated applications that are currently running on Windows Mobile, so it cannot be thought of as a successor to the Window Mobile platform. There are many new and great things you can do on WP7, but this constitutes a different kind of platform (one to compete with the iPhone). Will it grow to be a successor to Windows Mobile? How long will this take? What if it flops against the iPhone and never takes hold? Too many questions around the platform to invest a significant amount of development into it if you are not focused on creating iPhone type apps.

***** Since I posted this blog entry, I went to another TechEd and wrote another more updated post.

Wednesday, June 2, 2010

Preventing Tabs from being Selected

I tried several solutions I found on the internet to prevent tabs from being selected with a TabControl, but the link below shows the only solution that worked well. My task was very simple, I didn't want the user to select other tabs until the first tab contained valid information. The trick was to use the Deselecting event on the TabControl. In the event, see which tab you are on (SelectedIndex) and perform your validation specific to the tab. If the validation fails, set the event's e.Cancel to True and the tab won't change.

Tuesday, June 1, 2010

XPath Query Syntax

The following link give a good review of the XPath Query syntax:

Wednesday, May 26, 2010

Checkboxes in any Cell in a ListView

The built-in Checkbox functionality for ListViews will put a checkbox at the beginning of each row. I only needed to put the check box at the beginning of certain rows. The following posting show a simply way to achieve this requirement. I did not use this method exactly as it is shown, but it was definitely a good start:

Thursday, May 13, 2010

DiffMerge - Tool to Compare and Merge Files

A free tool to compare and Merge files and folders:

Saturday, April 24, 2010

VB.NET and C# Comparison

Great posting that compares VB.NET and C#:

Friday, April 23, 2010

Sorting Collections (Generic.List)

Here is a simple example for sorting collections (such as a Generic.List) based on particular attributes in the objects:

Here is another:

Serializing Objects in .NET as XML or Binary

This posting provides a good summary of serializing .NET Objects as XML or Binary:

Wednesday, March 31, 2010

Rectangle Structure

Here is a pretty good link that shows all of the different results using the different method from the Rectangle class such as Union, Intersection, Inflate, etc.:

Tuesday, March 2, 2010

Simple XOR String Encryption

Here is a posting I found on how to Encrypt Strings with an XOR operation:

Friday, February 19, 2010

Memory Mapped Files in .NET

Here is a link to info on using Memory Mapped Files in .NET:

Friday, January 15, 2010

Setting the WCF MaxBufferSize, MaxReceiveMessageSize, and MaxArrayLength in Code instead of App.config

While the concept of using the app.config file for configuring the many WCF parameters is a nice idea. I sometime like setting the values in code. The most common one for me are MaxBufferSize, MaxReceiveMessageSize, and maxArrayLength because they are usually too small by default for most of my applications. Below I showthe app.config file with these parameters set and then how you can set the same parameters with code in C# and VB.NET.



' Increase binding max sizes so that the image can be retrieved
If TypeOf pltSvr.Endpoint.Binding Is ServiceModel.BasicHttpBinding Then
Dim binding As ServiceModel.BasicHttpBinding = _
CType(pltSvr.Endpoint.Binding, ServiceModel.BasicHttpBinding)
Dim max As Integer = 5000000 ' around 5M size allowed
binding.MaxReceivedMessageSize = max
binding.MaxBufferSize = max
binding.ReaderQuotas.MaxArrayLength = max
End If


// Increase binding max sizes so that the image can be retrieved
if (pltSvr.Endpoint.Binding is System.ServiceModel.BasicHttpBinding)
System.ServiceModel.BasicHttpBinding binding =

int max = 5000000; // around 5M
binding.MaxReceivedMessageSize = max;
binding.MaxBufferSize = max;
binding.ReaderQuotas.MaxArrayLength = max;