Wednesday, September 12, 2012

Programmatically setting blank date value in InfoPath form Date Picker.

 XPathNavigator Root = MainDataSource.CreateNavigator();   
 XPathNavigator node = Root.SelectSingleNode(path, NamespaceManager);  
 if (node.MoveToAttribute("nil", System.Xml.Schema.XmlSchema.InstanceNamespace))  
 {  
   node.DeleteSelf();  
 }  
 node.SetValue(value);  
 if (string.IsNullOrEmpty(value)) //Empty date  
 {  
   string nil = node.GetAttribute("nil", System.Xml.Schema.XmlSchema.InstanceNamespace);  
   if (string.IsNullOrEmpty(nil))  
   {  
     try  
     {  
       node.MoveToFirstChild();  
       node.DeleteSelf();  
       node.CreateAttribute("xsi", "nil", System.Xml.Schema.XmlSchema.InstanceNamespace, "true");  
     }  
     catch (Exception ex)  
     {  
     }            
   }          
 }  

No comments: