Infopath multiple selection check boxes

I had an issue at work where we had to create a checkbox section with some values in Infopath. Whatever a user checks will get sent to the database separated by a semicolon. We decided to use multiple-selection list boxes because we wanted to allow the user to select more than one checkbox. So we defined some rules and created a sample hidden field which will keep track of all the values selected separated by semicolon. The issue came when we had to uncheck a box. There was no rule we could apply to update our text box after a user unchecked a box. So we found this solution:

If you are using infopath 2010, go to developer tab and click on Content Changed Event. This will open up code view with a function already defined for you. You just have to add this code in between the curly brackets:


//Data Source Navigator
XPathNavigator mainXN = this.MainDataSource.CreateNavigator();
//Namespace Manager
XmlNamespaceManager ns = this.NamespaceManager;
//Node Itterator, so we can loop through the selected items
XPathNodeIterator xi = mainXN.Select("/dfs:myFields/my:BoxMulti", ns); //replace BoxMulti with the name of your multiple selection box
//Reference to the field we want to add the selected items to
XPathNavigator semicolonList = mainXN.SelectSingleNode("/dfs:myFields/my:textfield", ns); //replace textfield with the name of your hidden text field
//Clear the field before we write to it. This will cover unchecking an item, too.
semicolonList.SetValue("");
//Loop through the selected item.
while (xi.MoveNext())
{
//If the item is not blank
if (xi.Current.InnerXml != "")
{
//Concatenate the item to the field, separated by a semicolon
semicolonList.SetValue(semicolonList.Value + xi.Current.InnerXml + "; ");
}
}

Hope this works for you!

If you want to create a simple multiple selection list box without code, you can follow instructions on this site:

http://office.microsoft.com/en-us/infopath-help/insert-a-multiple-selection-list-box-HA010081961.aspx

Posted in C#, infopath | Tagged , , , | Leave a comment

Two or more Web modules defined in the configuration have the same context root

Recently I have been playing around with Eclipse and Tomcat for a class project. Today I decided to debug something and after I was done, I couldn’t run my code. I kept getting the “Two or more Web modules defined in the configuration have the same context root” error. It had me pulling out my hair for an hour. Finally figured out the solution. Here it is:

note:I have indigo version of Eclipse.
On the left hand side, expend the Servers folder and edit server.xml. Look for two occurrences of the same line. The line will look like the following, where “someApplication” would be your context root.


Context docBase="someApplication" path="/someApplication" reloadable="true" source="org.eclipse.jst.jee.server:someApplication"

Hit Ctrl+F and look for “docBase”, if you see two lines which look alike, delete one of them.

Posted in Uncategorized | Leave a comment

Extract Data from XML using C#

This code will take data from InfoPath document (xml) and print it out. You will need to modify it for your needs.


//Import in the xml
bool flag = true; //to stop the while loop

//load xml file
StreamReader xmlStream = new StreamReader("doc.xml");
XmlDocument xmlDocument = new XmlDocument();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("dfs", "schema1");
nsmgr.AddNamespace("d", "schema1");
nsmgr.AddNamespace("xdado", "schema1");
XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
XmlReaderSettings xset = new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Fragment };
XmlReader rd = XmlReader.Create(xmlStream, xset, context);
xmlDocument.Load(rd);

//get the root
XmlNode root = xmlDocument.DocumentElement.FirstChild;

//get the first child
XmlNode child = root.FirstChild;

//get the child's sibling
child = root.NextSibling;

//get that child's first child
child = child.FirstChild;

//While we still have data
while (flag == true && child != null)
{
//get all the attributes of the child. This is all of the stuff in the quotes

XmlAttributeCollection attr = child.Attributes;
//loop through all child attribues and print them out.
for (int i = 0; i 0)
{
Console.WriteLine("keep going....");
child = child.FirstChild;
}
else
{
//child = child.NextSibling;
if (child.NextSibling != null)
{
child = child.NextSibling;
Console.WriteLine("keep going...");
}
else
{
XmlNode parent = child.ParentNode;
child = parent.NextSibling;
}
}
}

Here’s a simple pseudo code in case you are confused:


flag = true
load xml
get root
get child
get sibling
get child

if (true)
get child
get all attributes
if next child exists. go back to loop
else
get sibling
if sibling exist. go back to loop.
else
get parent. get sibling
if sibling exist go back to loop
else
flag = false;

Posted in C#, QC | Tagged | Leave a comment

Automatically add requirements to Quality Center using C#

This is my new project at work. I have to take requirements from an InfoPath document and export them to QC11 (ALM). There are a lot of documentation for VB but not much for C# (which is why I am posting this). There are two parts to this process. First i’ll have to extract data from the InfoPath document and then connect to QC and add the requirements. I’ll post the XML part later. For now, Here’s how you can connect to QC and add a dummy requirement using C#.


//Declare an object of TDCoonection
TDConnection qctd = new TDConnection();
//Pass the QC server URL
qctd.InitConnectionEx("http://yourserver:port/qcbin");
//Connect with the QC
qctd.ConnectProjectEx("domain name", "project name", "userid", "password");
bool check = qctd.LoggedIn;

ReqFactory myReqFactory = (ReqFactory)qctd.ReqFactory;
Req myReq = (Req)myReqFactory.AddItem(DBNull.Value);
myReq.Name = "new requirement";
// 0=Business, 1=Folder, 2=Functional, 3=group, 4=testing
myReq.TypeId = "1";
myReq.ParentId = 0;
myReq.Post();

Posted in C#, QC, Uncategorized | Leave a comment

Change the default path of Command Prompt

If you are trying to run your code from the command prompt and you have to navigate to your project directory every time, it gets annoying after a while. You can change the default path in the registry but that might break something else. Here is a simple solution:
1) Navigate to command prompt from the start menu.
2) Right click and create a shortcut
3) Right click and go to properties
4) Change the “start in ” path to the path of your project
Note: you can drag the shortcut icon to the task bar section near the start button for easy access.

Posted in command prompt, Useful Stuff | Leave a comment

Getting started with Protovis

I am taking a visual analytics class and we have to do a project to create parallel coordinates using one of the visualization toolkits. The parallel coordinates have to be interactive. I have never used protovis or javascript before, so after searching on the web, i found this very helpful video which helps beginners setup protovis and create their first visualization:

http://multimedia.journalism.berkeley.edu/tutorials/protovis-javascript-charts-part-1/

The video uses a fancy editor which gives you a live view of how your code will look in the browser. I wanted something free :) so found, komodo edit which does the same thing. you can download it here:

http://www.activestate.com/komodo-edit

Posted in protovis | Tagged , , , | Leave a comment

Entry point QtCore4.dll error

If you see the error “Entry point for function _Z5qFreePV not found in QtCore4.dll.” while trying to run qt code, most likely you have an another QtCore4.dll sitting somewhere. Do a search for QTCore4.dll and see if you have more than one.

Posted in QT | Tagged , , , | Leave a comment

Compare Excel Workbooks

Workbook1 = “C:\Documents and Settings\GXK4180\My Documents\Downloads\sheet1.xlsx”
Workbook2 = “C:\Documents and Settings\GXK4180\My Documents\Downloads\sheet2.xlsx”

WorkBook1SheetNum = 1
WorkBook2SheetNum = 1

Set ExcelObj = CreateObject(“Excel.Application”)
ExcelObj.Visible = True

Set BookObj1 = objExcel.Workbooks.Open(Workbook1)
Set BookObj2 = objExcel.Workbooks.Open(Workbook2)

Set SheetObj2 = BookObj2.Worksheets(WorkBook1SheetNum)
Set SheetObj1 = BookObj1.Worksheets(WorkBook2SheetNum)

For Each cell In SheetObj1.UsedRange
If cell.Value SheetObj2.Range(cell.Address).value then
cell.Interior.ColorIndex = 3
else
cell.Interior.ColorIndex = 0
End If
Next

Set objExcel = nothing

Posted in Uncategorized | 1 Comment

Mount iso image in virtual cd drive

If you ever download something and its an image file (.iso), you have two options. Either you can burn it to a cd or you can mount it to a virtual cd drive.

To mount it to a virtual cd drive, you need to download Virtual CD-Rom control panel for windows xp from Microsoft website :

Virtual CD-Rom Download

After you download and upzip it:
1. Double click on VCdControlTool.exe
2. Click on ‘Driver Control’
3. Click on Install Driver button. Navigate to the folder where you unzipped the software and locate
and double click on the file called: VCdRom.sys
4. Click Start
5. Click OK
6. Click ‘Add Drive’. Select an unused drive
7. Click Mount
8. Find the image (.iso) that you wanted to mount and click OK.

Now you can go to My Computer and double click on the drive that you just created. It will act as if you were using a regular cd.

UPDATE: virtual cd drive doesn’t work for vista or windows 7. For vista or windows 7 use Virtual Clone Drive.
Download it from here:

Virtual Clone Drive Download

Posted in Useful Stuff | Tagged , , , | Leave a comment

Batch Script

In windows, you can create batch file using notepad. Type in your commands in notepad and when you save it make sure to select “all files” under “Save as file”. Name the file with the extension .bat.
For example: myfile.bat
After you have created and saved the file, double click to run it.

To copy folders from one directory to another:

Simple way of doing it:

xcopy “X:\webservices\tubWebService” “C:\movefolder” /s

Above will copy whatever is in folder tubwebservice to the folder movefolder

Below are additional options for the xcopy command:

XCOPY source [destination] [/A | /M] [/D[:date]] [/P] [/S [/E]] [/V] [/W] [/C] [/I] [/Q] [/F] [/L] [/H] [/R] [/T] [/U] [/K] [/N] [/O] [/X] [/Y] [/-Y] [/Z] [/EXCLUDE:file1[+file2][+file3]…]

source Specifies the file(s) to copy.
destination Specifies the location and/or name of new files.
/A Copies only files with the archive attribute set, doesn’t change the attribute.
/M Copies only files with the archive attribute set, turns off the archive attribute.
/D:m-d-y Copies files changed on or after the specified date. If no date is given, copies only those files whose source time is newer than the destination time.
/EXCLUDE:file1[+file2][+file3]… Specifies a list of files containing strings. When any of the strings match any part of the absolute path of the file to be copied, that file will be excluded from being copied. For example, specifying a string like \obj\ or .obj will exclude all files underneath the directory obj or all files with the .obj extension respectively.
/P Prompts you before creating each destination file.
/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T.
/V Verifies each new file.
/W Prompts you to press a key before copying.
/C Continues copying even if errors occur.
/I If destination does not exist and copying more than one file, assumes that destination must be a directory.
/Q Does not display file names while copying.
/F Displays full source and destination file names while copying.
/L Displays files that would be copied.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/T Creates directory structure, but does not copy files. Does not include empty directories or subdirectories. /T /E includes empty directories and subdirectories.
/U Copies only files that already exist in destination.
/K Copies attributes. Normal Xcopy will reset read-only attribute
/N Copies using the generated short names.
/O Copies file ownership and ACL information.
/X Copies file audit settings (implies /O).
/Y Suppresses prompting to confirm you want to overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite an existing destination file.
/Z Copies networked files in restartable mode.

To copy a file:
copy a:\readme.txt a:\windows\help.txt

To delete file:
del filename

To rename a file:
Ren oldfile newfile

Posted in batch script | Leave a comment