InfoPath 2007 - adding an attribute and childNodes through Managed Code - infopath-2007

I’m converting my InfoPath 2003 Object Model Codes to InfoPath 2007 Managed Code, I want to add an attribute and childNodes to a section of form on form load event (FormEvents_Loading). I want to update the following section:
I was to add an attribute to mstns:SpecificBook node and a few child node. The result should be:
My InfoPath 2003 Object Model code
To Adding and Set attribute values:
flag = TheXDocument.DOM.createAttribute("active")
prereqsNode.attributes.setNamedItem(flagNode).text = "true"
newNode = doc.CreateNode(NodeTypeElemt, FromNamespacePrefix, "Book",FormNamespace)
specificBookAttrib = newNode.OwnerDocument.CreateAttribute("BookId")
specificBookIdAttrib.Value = “anybook”
newNode.Attributes.Append(specificBookIdAttrib)
SpecificBookNode.AppendChild(newNode)
Can anybody help me convert the line above use Manage code?

Since I could create a new attribute because the sampledata.xml had a default value although my Template.xml have none; I could not it set that value because it read only.
prereqsNode = navigator.SelectSingleNode (“//mstns:SpecificBook”, Me.NamespaceManager)
*Error “Duplicate attribute”
prereqsNode.CreateAttribute("", "areLoaded", "", "true")
Error “Read only”
prereqsNode.SetValue("true")*
I decided to create a new XmlDocument:
create a new attribute replace the
entire mstns:SpecificBook node
I also used XmlDocument to create the childNodes, convert the node to navigator and then append childNodes.
Dim doc As XmlDocument = New XmlDocument
Dim newNode As XmlNode
Dim activeAttrib As XmlAttribute
activeAttrib = newNode.OwnerDocument.CreateAttribute("active")
activeAttrib.Value = True
newNode.Attributes.Append(activeAttrib)
specificBookNode.ReplaceSelf(newNode.OuterXml)

Related

Append to meeting invite body with or without Redemption

We are developing an Outlook VSTO add-in.
Right now I am trying to append some information to a meeting invite the user is in the process of composing. I want the content to appear in the body like what clicking the Teams-meeting button would do, where formatted text and links are appended to the end of the body.
Since the content is HTML and the Outlook Object Model does not expose an HTMLBody property for AppointmentItems, I try to set it via Redemption:
// Dispose logic left out for clarity but everything except outlookApplication and outlookAppointment is disposed after use
Application outlookApplication = ...;
AppointmentItem outlookAppointment = ...; // taken from the open inspector
NameSpace outlookSession = outlookApplication.Session;
RDOSession redemptionSession = RedemptionLoader.new_RDOSession();
redemptionSession.MAPIOBJECT = outlookSession.MAPIOBJECT;
var rdoAppointment = (RDOAppointmentItem)redemptionSession.GetRDOObjectFromOutlookObject(outlookAppointment);
string newBody = transform(rdoAppointment.HTMLBody); // appends content right before HTML </body> tag
rdoAppointment.BodyFormat = (int)OlBodyFormat.olFormatHTML;
rdoAppointment.HTMLBody = newBody;
Problem
The Outlook inspector window is not updating with the appended content. If I try to run the code again, I can see the appended content in the debugger, but not in Outlook.
Things I have tried:
Saving the RDOAppointmentItem
Also adding the content to Body property
Using SafeAppointmentItem instead of RDOAppointmentItem; didn't work because HTMLBody is a read-only property there
Setting PR_HTML via RDOAppointment.Fields
Paste the HTML via WordEditor (see below)
Attempt to use WordEditor
Per suggestion I also attempted to insert the HTML via WordEditor:
// Dispose logic left out for clarity but everything except inspector is disposed after use
string htmlSnippet = ...;
Clipboard.SetText(htmlSnippet, TextDataFormat.Html);
Inspector inspector = ...;
Document wordDoc = inspector.WordEditor;
Range range = wordDoc.Content;
range.Collapse(WdCollapseDirection.wdCollapseEnd);
object placement = WdOLEPlacement.wdInLine;
object dataType = WdPasteDataType.wdPasteHTML;
range.PasteSpecial(Placement: ref placement, DataType: ref dataType);
... but I simply receive the error System.Runtime.InteropServices.COMException (0x800A1066): Kommandoen lykkedes ikke. (= "Command failed").
Instead of PasteSpecial I also tried using PasteAndFormat:
range.PasteAndFormat(WdRecoveryType.wdFormatOriginalFormatting);
... but that also gave System.Runtime.InteropServices.COMException (0x800A1066): Kommandoen lykkedes ikke..
What am I doing wrong here?
EDIT: If I use Clipboard.SetText(htmlSnippet, TextDataFormat.Text); and then use plain range.Paste();, the HTML is inserted at the end of the document as intended (but with the HTML elements inserted literally, so not useful). So the general approach seems to be okay, I just can't seem to get Outlook / Word to translate the HTML.
Version info
Outlook 365 MSO 32-bit
Redemption 5.26
Since the appointment is being displayed, work with the Word Object Model - Inspector.WordEditor returns the Document Word object.
Per Dmitrys suggestion, here is a working solution that:
Shows the inserted content in the inspector window.
Handles HTML content correctly with regards to both links and formatting (as long as you stay within the limited capabilities of Words HTML engine).
using System;
using System.IO;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
using Word = Microsoft.Office.Interop.Word;
namespace VSTO.AppendHtmlExample
{
public class MyExample
{
public void AppendAsHTMLViaFile(string content)
{
// TODO: Remember to release COM objects range and wordDoc and delete output file in a finally clause
Outlook.Inspector inspector = ...;
string outputFolderPath = ...;
string outputFilePath = Path.Combine(outputFolderPath, "append.html");
Word.Document wordDoc = inspector.WordEditor;
File.WriteAllText(outputFilePath, $"<html><head><meta charset='utf-8'/></head><body>{content}</body></html>", Encoding.UTF8);
Word.Range range = wordDoc.Content;
range.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
object confirmConversions = false;
object link = false;
object attachment = false;
range.InsertFile(fileName,
ConfirmConversions: ref confirmConversions,
Link: ref link,
Attachment: ref attachment);
}
}
}

Infopath 2010 > is multiple selection list box allowed for Browser

I may be missing something. I have a Multiple Selection List box in a Section. See attached pic. When I right click on the grpApplications and copy XPath it gives me /my:myFields/my:grpAccessOfficeEquipment/my:grpApplications when I right click for XPath on the fldApplicatins it gives me /my:myFields/my:grpAccessOfficeEquipment/my:grpApplications/my:fldApplications
In the code (code posted below) I am referencing the /my:myFields/my:grpAccessOfficeEquipment/my:grpApplications/my:fldApplications and I get no value. but I used /my:myFields/my:grpAccessOfficeEquipment/my:grpApplications I get a value for selected item in the listbox.
But I am still getting error NullReferenceException "object reference not set to an instance of an object" on string appName line. The AppID looks like this "\n\t\t\t262265264143\n\t\t" instead of whole number in debug. but when I click on the binocular is shows 262265264143 but with spaces/lines before and after this
XPathNavigator MainDS = MainDataSource.CreateNavigator();
XPathNodeIterator iterApp = MainDS.Select("/my:myFields/my:grpAccessOfficeEquipment/my:grpApplications", NamespaceManager);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
while (iterApp.MoveNext())
{
string AppID = iterApp.Current.Value;
//int lookupID = Convert.ToInt16(value);
XPathNavigator secAPPDS = DataSources["SupportEscalationList"].CreateNavigator();
string appName = secAPPDS.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW[#ID = '" + AppID + "']/#ApplicationProcess", NamespaceManager).Value;
sb.Append(appName);
item["ApplicationProcess"] = sb.ToString(); // because applicationprocess column in target sp list is single text type column
}
Says here multiple selection list boxes are supported in 2010 browser forms but not 2007 browsers forms. Hope that helps.
http://office.microsoft.com/en-us/infopath-help/infopath-2010-features-unavailable-in-web-browser-forms-HA101732796.aspx

Set dataSource of ListView programmatically

I'm trying to update a windows 8 application from the Developer Preview to the Consumer Preview. It seems there's been a few changes. This code used to work:
var myDataSource = new WinJS.UI.ArrayDataSource(array)
var basicListView = WinJS.UI.getControl(document.getElementById("basicListView"));
basicListView.dataSource = myDataSource;
Now, there is no WinJS.UI.getControl method and no ArrayDataSource. This is my code:
var dataList = new WinJS.Binding.List(array);
var list = document.getElementById("basicListView");
list.itemDataSource = dataList.dataSource;
but it does nothing (except add a property to a DOM element that is ignored). Any ideas what I'm missing?
Got it. To get the control you now use the winControl property of the element:
var list = document.getElementById("basicListView").winControl;
Setting the itemDataSource works a treat.

creating table at runtime in vb.net, image control doesnt have imageurl proerty

i am creating a table in vb.net code (htmltable) with htmltablerows and htmltablecell. I gave on image control but thatr control cant have the .imageurl property, which i need cause i have a handler image.ashx which brings image from the database.
heres' the code -
TD = New HtmlTableCell
Dim img As New HtmlImage()
img.ID = "image_" & rd("ID")
img.Style.Add("width", "100px")
img.Style.Add("height", "100px")
img.ImageUrl = "Image.ashx?id=" & rd("ID")
on the last line, "img.ImageUrl" i get this error -
'ImageUrl' is not a member of 'System.Web.UI.HtmlControls.HtmlImage'
how do i fix this?
ImageUrl is a member of the System.UI.WebControls.Image control. By contrast, you are using the direct HtmlImage control which is rendered exactly as an img tag would be. You should use the Src property of the HtmlImage control instead.

Dynamically Created LABEL Element not showing up in XUL application

I'm trying to dynamically create a set of labels in my XUL Runner application. I have an HBox like so:
<hbox class="upload-attachments"></hbox>
If I manually assign a label element to it like so:
<hbox class="upload-attachments"><label value="test" /></hbox>
It works fine. Also, when I query the object in Javascript I can access the test label.
When I try and create new label elements programmatically it fails. This is roughly what I am doing:
var attachments = view.query_first('.upload-attachments');
var label = view.ownerDocument.createElement('label');
label.value = "Some value."
attachments.appendChild(label);
var childCount = attachments.childNodes.length;
The query_first method is just a call to the Sly Query Selector engine and in other cases works fine. The childCount value is updating appropriately, and as I said, I can access and manipulate any labels I manually add to the hbox.
Thanks in advance,
Either append it with the attribute set, or set the property after inserting:
var label = view.ownerDocument.createElement('label');
attachments.appendChild(label);
label.value = "Some value."
-- or --
var label = view.ownerDocument.createElement('label');
label.setAttribute("value", "Some value.");
attachments.appendChild(label);
The reasoning being that, before the element was inserted, the property setters don't work.