Format matters! So if you ever tried to set a date value to an infopath form by using code behind, you might got this really nice displaying with a beautiful red dotted border:
Why? It’s easy – cause you have to format the date in the right way InfoPath expects it! InfoPath expects it this way: yyyy-mm-dd.
Well that’s easy. But in order to overwrite the value of a datefield, you have to insert these lines of code in order to overwrite a date field with string values! So i didn’t test it without this function:
public void DeleteNil(XPathNavigator node)
if (node.MoveToAttribute(“nil”, “http://www.w3.org/2001/XMLSchema-instance“))
After that you can use this function in order to set attribute and overwrite the field by setting the value as you desire.
//In order to overwrite the field with datetime
//Opening the access to the field of the form
XPathNavigator navForm = this.CreateNavigator();
XmlNamespaceManager NS = this.NamespaceManager;
DateTime getDate = Convert.ToDateTime(dr[“CreateDate”]);
string convDate = getDate.ToString(“yyyy-MM-dd”);
And it looks like a normal date field:
As you can see the red dotted validation does not show up.
..:: I like SharePoint ::..