I did this with WiX custom action in a DLL as well. Here is the code:
WiX:
<Binary Id="CustomAction" SourceFile="$(var.SourceBinFolder)\MyCustomAction.CA.dll" />
<CustomAction Id="CheckFolderCustomAction" BinaryKey="CustomAction" DllEntry="CheckFolder" />
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
<Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="CheckFolderCustomAction" Order="2">1</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="3">InstallDirOk = "1"</Publish>
Custom Action:
public class CustomActions
{
[CustomAction]
public static ActionResult CheckFolder(Session session)
{
string installDir = session["INSTALLFOLDER"];
installDir = installDir.Trim();
session["InstallDirOk"] = "1";
if (Directory.Exists(installDir) && Directory.EnumerateFileSystemEntries(installDir, "*", SearchOption.TopDirectoryOnly).Any())
{
if (DialogResult.No == MessageBox.Show(
string.Format("Selected folder \"{0}\" is not empty. This might cause existing files to be overwritten. Do you want to proceed?", installDir),
"Please confirm",
MessageBoxButtons.YesNo))
{
session["InstallDirOk"] = "0";
}
}
return ActionResult.Success;
}
}