Error Message: Retrieving the COM class factory for component with CLSID {C5CBD7B2-490C-45F5-8C40-B8C3D108E6D7} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)) ota

If you are getting this error, you are probably using a x64 bit machine. To fix this error, Right-click the project node in Solution Explorer and click Properties. Click on Configuration Properties.Click on Configuration Manager. click on New under Platform and change it to x64 and see if it fixes the problem. If it doesn’t then change the platform to x86.

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

Note: I am assuming you have a form created in C#.

1) Create a Rich Text Box on the form. Right click on the box and open Properties. Under Design , change the name to: path (or whatever you want to call it)
2) Add a button to the form and name it “Browse”
3) Now double click on the button and code will open.
4) Inside the button_Click event, you want to post this code:

OpenFileDialog browseFile = new OpenFileDialog();
browseFile.Filter = "XML Files (*.xml)|*.xml";
browseFile.Title = "Browse XML file";
if (browseFile.ShowDialog() == DialogResult.Cancel)
path.Text = browseFile.FileName;
catch (Exception)
MessageBox.Show("Error opening file", "File Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

This code is for XML File but you can change the value in the Filter for any other type of file.

Posted in C#, QC, Useful Stuff | Leave a comment

C# error fix: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made

If you see this error when you try to run your code An unhandled exception of type'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll. Additional information: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.

Add this before the main function:

So your code will look like:

class Program
static void Main(string[] args)
//something something

Posted in Uncategorized | Leave a comment

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.
//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:

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 | 2 Comments

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);

//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;
//child = child.NextSibling;
if (child.NextSibling != null)
child = child.NextSibling;
Console.WriteLine("keep going...");
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
get sibling
if sibling exist. go back to loop.
get parent. get sibling
if sibling exist go back to loop
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
//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;

Posted in C#, QC, Uncategorized | 2 Comments