dotnet thoughts 

a dotnet developer's technical blog

Displaying image in WPF image control

Unlike in .Net 2.0, the image control have a new type of source class, called Windows.Media.ImageSource. While writing simple WPF application I want to display an image in a Image control. But Windows.Media.ImageSource is abstract class, where I can’t create the object.

After googling I found a solution.

Image1.Source = New BitmapImage(New Uri(FlOpenDlg.Filename)) 'New Uri(Filename or address as string), so I passing the Open File Dialog's Filename property as the argument.

XPath query in Infopath forms

While working in Infopath, some times it is required to Query Infopath forms using XPath and XmlDocument. But the Infopath XML contains a “my” prefix. So simple XDocument.Select will throw the an XPath exception – Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function. To fix this issue you need a namespace manager object which required to query Infopath forms.

Dim doc As New System.Xml.XmlDocument
doc.Load("D:\Infopath.xml")
Dim node As Xml.XmlNode = doc.SelectSingleNode("//my:Root") 'It will throw error because it doesn't have the Namespace.

Function will return the Namespace Manager based on the document given.

Function GetNameSpaceManager(ByVal Document As XmlDocument) As XmlNameSpaceManager
Dim objXmlNamespaceManager As New XmlNamespaceManager(Document.NameTable)
objXmlNamespaceManager.AddNamespace("my", Document.DocumentElement.GetNamespaceOfPrefix("my"))
Return objXmlNamespaceManager
End Function

And you can query infopath like this.

Dim doc As New System.Xml.XmlDocument
doc.Load("D:\Infopath.xml")
Dim node As Xml.XmlNode = doc.SelectSingleNode("//my:Root", GetNameSpaceManager(doc))