Tuesday, October 9, 2012

TIP - Set StartUp Project in Visual Studio solution file

When Visual Studio opens a solution (.sln), the default StartUp project is the first project listed in the solution file. 

The default StartUp project can be overridden by the developer by changing the StartUp project manually through the context menu. Visual Studio will see it as a user-specific preference and hence store this within its '.suo' file. 

The rule is "if you don't have a .suo file in your solution directory, Visual Studio picks the first one as the default StartUp project". 

Now, for projects on a source code repository, it is not advisable to store the 'suo' file. This means that each time a fresh checkout of the code is done, the default StartUp project is used when Visual Studio opens the solution. 

TIP: to change the default StartUp project, 

1) Open the solution file (.sln) in a text editor (e.g. notepad) 
2) You will see all your project entries within the solution encapsulated in a Project ... EndProject lines. 
3) Cut and paste the desired StartUp project to the top position. 
4) Commit your updated solution file (.sln) on the code repository 

And in the next fresh checkout, you have the correct StartUp project ;-)

Sunday, April 25, 2010

Determine list of printers installed in C# (.Net Framework)

1. Add System.Drawing library as reference.

2. Import the System.Drawing.Printing.
using System.Drawing.Printing;

3. PrinterSettings.InstalledPrinters is a string collection of the printer names installed on the machine

Example to output all printers on Console:

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Printing;
using System.Windows.Forms;

namespace PrintersDemo
    class Program
        static void Main(string[] args)
            for(int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++)


JDeveloper: ORA-01882: timezone region found found

When trying to deploy your web application using JDeveloper to the integrated WebLogic, if you get the following error:

(oracle.jbo.JboException) JBO-29000: Unexpected exception java.sql.SQLDataException, msg=ORA-01882: timezone region not found

then to resolve this issue,

1. Goto Application menu and select Project Properties
2. In the Project Properties window, On the left pane, select Run/Debug/Profile
3. On the right pane, Edit the Default configuration (or double click on Default)
4. In the Edit run configuration window, select Launch Settings
5. For 'Java option' text box, add -Duser.timezone="+04:00"

You will probably need to save and restart JDeveloper for the changes to take effect.

Saturday, April 24, 2010

Command to launch Remote Desktop Connection

Just type mstsc in the Run window or the command prompt window, and the Remote Desktop Connection window will pop up ...

Thursday, June 11, 2009

GetDeviceVersion() in RAPI fix

I have got a desktop application that determines the operating system's version of the device (I have used a Windows Mobile 5.0 device) connected to PC via ActiveSync. When calling the method GetDeviceVersion() exposed in the RAPI class in the OpenNETCF.Desktop.Communication library, the application crashes with the following exceptions:

When running the solution in Debug configuration:
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."

When running the solution in Release configuration:
System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

When running the exe application:
Unhandled exception at 0x00000000 in XXXApplicationNameXXX.exe: 0xC0000005: Access violation reading location 0x00000000.

The solution to any of these issues is to PInvoke the method CeGetVersionEx() rather than the one provided in the RAPI class.

//PInvoke Declarations


    CharSet = CharSet.Unicode)]



    internal int dwOSVersionInfoSize;

    public int dwMajorVersion;

    public int dwMinorVersion;

    public int dwBuildNumber;

    public PlatformType dwPlatformId;

    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]

    public string szCSDVersion;




    CharSet = CharSet.Unicode,

    SetLastError = true)]

internal static extern int

    CeGetVersionEx(ref CEOSVERSIONINFO lpVersionInformation);

//PInvoke Call


CeGetVersionEx(ref osVersionInfo);

Source: opennetcf

Thursday, May 28, 2009

Adding the XML Declaration when calling DataSet.WriteXml(Stream stream) method

using (DataSet ds = new DataSet())


//TODO: fill the ds with appropriate data

XmlTextWriter stream = new

XmlTextWriter(@"C:/xmltest.xml", Encoding.UTF8);




The above example attempts to write the content of the DataSet to an xml file using the DataSet.WriteXml method. The xml file doesn't contain the XML declaration.

Content of xml file:

<NewDataSet />

TIP: To include the XML declaration in the output file, call the method WriteStartDocument() on the stream object prior to the WriteXml() method call.

using (DataSet ds = new DataSet())


//TODO: fill the ds with appropriate data

XmlTextWriter stream = new

XmlTextWriter(@"C:/xmltest.xml", Encoding.UTF8);





Content of xml file:

<?xml version="1.0" encoding="utf-8"?>

<NewDataSet />