InfoPath: Update DateTime Field/Attribute using C#
Updating the Field/Attribute is rather easy, the problem is when that Field/Attribute is displayed in a date picker control. The reason for it is the format of the DateTime string. In order, InfoPath to parse out the datetime correctly from the Field/Attribute and display it correctly (pass validation) you have to use the following formats:
1. For displaying dates only:”yyyy-MM-dd”
2. For displaying date and time: “yyyy’-'MM’-'dd’T'HH’:'mm’:'ss”
So right before you set the value in the XPathNavigator field/attribute, convert the date you want to use to a string using one of the two formats above.
Example:
DateTime today=DateTime.Now;
XPathNavigator myfield=MainDataSource.CreateNavigator()
.SelectSingleNode("xpath to field",this.NamespaceManager);
String dateString=today.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
myfield.SetValue(dateString);
2 Responses to InfoPath: Update DateTime Field/Attribute using C#
Leave a Reply Cancel reply
Categories
Archives
Software Quotes
??Software Blogs
February 2012 M T W T F S S « Nov 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29






FYI:
today.ToStrong should be today.ToString
Thanks, fixed it.