Validation With Regular Expression

Ask general questions here.
Posts: 94
Joined: Tue Jun 16, 2009 10:27 pm

Validation With Regular Expression

Post by costamesakid » Mon Feb 08, 2010 11:17 pm

I have a script that validates the correct default directory is displayed when the user saves an image using the application. The default directory should be:

C:\Documents and Settings\James\My Documents\System Manager

However, the username, in this case 'James' will change depending on what system the script is executed on. I tried to work around this problem by using a regular expression, but I cannot get my code to compile. Ranorex is showing the following error:

An object reference is required for the non-static field, method, or property 'ADSIasUserDefaultFileDir.SMImages.path' (CS0120)

Below is my code. Any help on this topic is greatly appreciated.

public partial class SMImages
public static string str = @"C:\Documents and Settings\*.*\My Documents\System
Regex path = new Regex(str);

static SMImages()
//Your recording specific initialization code goes here.

public static void Validate_TextC__Documents_and_Setting1()
//Your code here. Code inside this method will not be changed by the code
Validate.Attribute (repo.FormSave_Image.TextC__Documents_and_SettingInfo, "AccessibleValue", path);


User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Validation With Regular Expression

Post by Support Team » Tue Feb 09, 2010 9:35 am

Hi costamesakid,
you have to define Regex as static too if you want to use it in a static method

see msdn for more information about static: ... 71%29.aspx

Best regards,
Ranorex Team