SharePoint Experts, Information Architects, Expert Witness

SICG provides a broad array of business and technology consulting from architecture to design to deployment of global systems with a focus on surfacing data in the enterprise. We focus on the "How", not just the possible. Contact me direct: or call 704-873-8846 x704.

Search This Blog

Tuesday, March 25, 2008

VMWare installation on XP prompts for Host

Had this problem? Install VMWare on XP and for some reason, you cannot connect to the host? Unlike the other problem I've mentioned in another blog, this one has been troublesome...

The fix:

1) Make sure IIS is installed before you install VMWare - if you don't, uninstall and start again

2) After IIS is installed, disable the default web site then install VMWare

3) If neither of the above work, add your IP/Machine Name to the Hosts file

If none of the above work, you are likely missing a service pack or have an old copy of VMWare.

Get or Set the Windows Default Printer in C#

I like many of you, struggled to find all of the pieces needed to get or set the default printer for a system. This is particularly useful for InfoPath - the InfoPath Interop Assembly doesn't provide any way to set the printer - it will simply print to the default.

Having had this issue, the following code resolves it all - and by the way, I included what you need for using statements (hate when folks leave that out!):

using System.Runtime.InteropServices; // Needed for DLLs
using System.IO; // Needed for FileInfo (to open the file)
using System.Xml; // Needed for the XML document namespace (if using InfoPath)
using System.Management; // Needed to Get/Set the printer

namespace WindowsApplication1
public partial class Form1 : Form
// Code by David M. Sterling - Sterling International Consulting Group
// Add the function to return the default printer:
[DllImport("winspool.drv", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool GetDefaultPrinter(StringBuilder pszBuffer, ref int pcchBuffer);
private const int ERROR_FILE_NOT_FOUND = 2;
private const int ERROR_INSUFFICIENT_BUFFER = 122;
/// SetTheDefaultPrinter

/// Printer name as string
public int SetTheDefaultPrinter(string PrinterName)
int ReturnVal = 0;
string DeviceIdPath = "win32_printer.DeviceId='" + PrinterName + "'";
using (ManagementObject PrinterObj = new ManagementObject(DeviceIdPath))
ManagementBaseObject ReturnedParameters =
PrinterObj.InvokeMethod("SetDefaultPrinter", null, null);
ReturnVal = (int)(uint)ReturnedParameters.Properties["ReturnValue"].Value;
return ReturnVal;
/// GetDefaultPrinter

/// Printer name as string
public string GetDefaultPrinter()
int pcch_Buffer = 0;
if (GetDefaultPrinter(null, ref pcch_Buffer))
return null;
int lastWin32Error = Marshal.GetLastWin32Error();
StringBuilder psz_Buffer = new StringBuilder(pcch_Buffer);
if (GetDefaultPrinter(psz_Buffer, ref pcch_Buffer))
return psz_Buffer.ToString();
lastWin32Error = Marshal.GetLastWin32Error();
if (lastWin32Error == ERROR_FILE_NOT_FOUND)
return null;
return "Error : unable to obtain the current default printer";

private void Form1_Load(object sender, EventArgs e)
string TheNewPrinterName = "HP Deskjet 6800 Series";
string DefaultPrinterName = GetDefaultPrinter();
// Print away...
// ...
// When done:

Tuesday, March 18, 2008

Link to the Microsoft Office SharePoint Server 2007 The Complete Reference Site and Blog

Alas, while not published inside the book, the official site for "Microsoft Office SharePoint Server 2007 The Complete Reference" by Osborne/Mcgraw-Hill is:

(You might have thought mosstcr, but the name of the book changed!).

From this site you can view the local blog as well as download the source from the book and the bonus web chapter on the Business Data Catalog.

Button Click Event does not fire on the first click

Having come across this several times and forgotten how I'd fixed it, I figured this will help more than a few...

The problem occurs in Buttons, DataGrids and other event driven controls in Web Parts and Controls. On the first time through, the primary event (like the Click event on a button), the event does not fire. On the second click however, everything seems fine. If you follow through in Debug, you'll file that the event is actually skipped and the control proceeds to the render event.

In most cases, the fix is simple: one of the controls within the control/web part has AutoPostBack = true where it doesn't need it. Typically, this is a cut and paste error - for example, adding AutoPostBack to a TextBox.

This, by the way, though very odd, is somewhat expected. The invalid postback on the control tells ASP.NET that it's already happened, when indeed it hasn't since the specific control cannot perform the actual postback.

Saturday, March 15, 2008

VMWare Prompts for Host to login to after installation

For those of you that use VMWare (and Virtual Server) like I do, there can be a very annoying issue with VMWare after install in which it will prompt you for a Server to login to (note: this applies to VMWare 1.04). Regardless of what you enter, the login will fail usually with the message "target machine actively refused" the connection.

While not always a guaranteed fix, you can try this simple one. On the system in question, open a command prompt and enter:

gpupdate /force

This is will update the Group Policies on the local system (note that in some cases, you may have to reboot). Once complete, try opening VMWare Server again and you should see the normal local host option.

Sunday, March 2, 2008

Alerts (Immediate and Workflow) not working in WSS/MOSS

You may have an issue in which SharePoint Alerts are not being sent, though you receive an alert when it is created.

The primary issue centered around the Timer Service and a few jobs that must be running for alerts to work. A few things to check for first:

1) Verify the Timer service is running and that it's identity (running as) is the SharePoint Service account (Start > Control Panel > Administrative Tools > Services). Locate the SharePoint Timer service in the list and see if it is running. If not, right click on it and start it. If it stops again, the user is likely incorrect. Right click on it and select Properties then on the Identity tab, verify the account in use (Local Service or similar is NOT correct); set this to be the SharePoint Service account, close out the properties and try to start it again. If it stops again, you will have to go to the Domain Policies and make sure that the service account has "Run as a Service".

2) Verify the necessary jobs exist (SharePoint 3.0 Central Administration > Operations > Timer Job Definitions):
Immediate Alerts
Workflow Auto Cleanup
Workflow Failover

If they do exist, check the Timer Job Status (SharePoint 3.0 Central Administration > Operations > Timer Job Status) and see if any of these are displaying errors (you should also check the System Application Event Log).

If the jobs do not exist, you may be in for some work depending on the installation. If the site was a restore, you may have created an issue Microsoft has identified - you can see this solution here:

However, as I discovered with one of my clients, a site that had been migrated (not the situation explained in the link above) was missing these jobs. After much investigation, I was able to simply add the jobs as follows:

Login to the server, get down to the command line and set your directory to be the SharePoint bin folder (usually c:\program files\common files\microsoft shared\web server extensions\12\bin). Verify the STSADM.exe file (the SharePoint command line utility) is there to make sure you are in the right folder.

Add the jobs to the site experiencing the problem by adding the jobs manually as so (Note: you should ONLY do this for the job(s) missing).

First you can verify whether the job already exists by using the command:

stsadm -o getproperty -propertyname job-immediate-alerts -url http://yoursite:port

If the job does not exist, you will recieve a message:

Property Exist="No"

If the job does exist, you will see a different message, such as:

Property Exist="Yes" Value="every 5 minutes between 0 and 59"

(In both cases, the message preceeded by a left arrow and closed with a slash-right arrow; this blog will not permit me to enter the exact syntax as it interprets it as HTML).

Verify this for all the job types:

Job Type: Property Name:
Immediate Alerts job-immediate-alerts

Workflow job-workflow

Workflow Auto Cleanup job-workflow-autoclean

Workflow Failover job-workflow-failover

To add the individual jobs:

Immediate alerts:

stsadm -o setproperty -propertyname job-immediate-alerts -url http://yoursite:port -propertyvalue "every 5 minutes between 0 and 59"


stsadm -o setproperty -propertyname job-workflow -url http://yoursite:port -propertyvalue "every 5 minutes between 0 and 59"

Workflow Auto Clean:
stsadm -o setproperty -propertyname job-workflow-autoclean -url http://yoursite:port -propertyvalue "daily between 22:00:00 and 06:00:00"
Workflow Failover:
stsadm -o setproperty -propertyname job-workflow-failover -url http://yoursite:port -propertyvalue "every 15 minutes between 0 and 59"

Use the Get Property command to verify that the jobs are created. Note that the URL MUST BE SPECIFIED AND CORRECT or you will simply receive 'Property Exist="No"'.

Hope this helps! Sure beat trying to follow the Microsoft solution (which may or may not have corrected the problem).