Thursday, November 29, 2007

Lookup fields in custom activity and [%_x005f_String0%]

If you do a custom activity, configure it to use Lookup fields on field configured as DesignerType="StringBuilder" and instead of field value you get [%_x005f_String0%] you need to process this value with this function: public static string ProcessStringField ( string str, Activity activity, WorkflowContext context ) Here is a code sample:

//...
public static DependencyProperty __ContextProperty =
    DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(EmailActivity));
//...
[ValidationOption(ValidationOption.Optional)]public WorkflowContext __Context
{
get { return (WorkflowContext) base.GetValue(__ContextProperty); }
set { base.SetValue(__ContextProperty, value); }
}
//...
protected override ActivityExecutionStatus Execute(ActivityExecutionContext provider)
{
Activity parent = provider.Activity;
while (parent.Parent != null)
{
parent = parent.Parent;
}

string returnValue = Helper.ProcessStringField(stringToProcess, parent, this.__Context));
}

It seems that if you don't have WorkflowContext you can pass null
string returnValue = Helper.ProcessStringField(stringToProcess, parent, this.__Context));

Wednesday, November 21, 2007

Closing Form with WebBrowser control after window.close with C#

I recently had this problem. I have a Windows Form that hosts a WebBrowser control. The page in the WebBrowser control closes itself using window.close and when it does that the Windows Form freezes up.

Found a solution here posted by Jeff Sanders on his blog (thanks man!)

The sample code is provided in VB.NET Below is the same code rewritten in C#

public class ExtendedWebBrowser : WebBrowser
{
public const int WM_PARENTNOTIFY = 0x0210;
public const int WM_DESTROY = 2;

public delegate void ClosingEventHandler();
public event ClosingEventHandler Closing;

protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_PARENTNOTIFY:
if (!this.DesignMode)
{
if (m.WParam.ToInt32() == WM_DESTROY)
{
if (this.Closing != null)
{
this.Closing();
}
}
}
base.DefWndProc(ref m);
break;

default:
base.WndProc(ref m);
break;
}
}
}