..:: I like SharePoint ::.. Rotating Header Image

InfoPath

InfoPath Fill or empty a repeating table in browser-based form by using code-behind

InfoPath is a powerful tool which can be customized by using rules or custom code behind. At one of my projects it was necessary to display some additional information from a database dependent on which checkbox the user clicked / checked. Another request to this was that the form has to be browser-enabled cause it should be displayed in a SharePoint environment.

So i have 3 Checkboxes: A, B, C. And i have a section with a repeating table which is structured like this:
RepeatingTable
—–FieldA
—–FieldB
—–FieldC
—–FieldD
—–FieldE

I use the onchange Event of each Checkbox which calls the function. Now let’s see how we can fill this repeating table with data: (more…)

SharePoint 2010 & InfoPath Setting date field by using rules

I already posted about how to set a date field in infopath by code behind. If you like to read this post, just look at this post. But this post i am gonna explain how to set the date field correctly by just using rules or the formula.

So we should look at first at the anatomy of the date. Mostly you know the date as

  • 18.11.2012
  • 2012-11-18
  • 11/18/2012

or whatelse. It does not matter. You have your date field and set the format as you like. But you can see that infopath saves the date always in this way:

yyyy-mm-ddThh:mm:ss – example: 2012-11-18T12:00:00

If you know that, you are able to use formulas to fill a date field with correct dates. So you have to use a “T” as separator between the date and the time.

(more…)

InfoPath setting date value with code behind

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", "<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"))
node.DeleteSelf();
}


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;

DeleteNil(navForm.SelectSingleNode("/my:meineFelder/my:CreationDay", NS));

DateTime getDate = Convert.ToDateTime(dr["CreateDate"]);

string convDate = getDate.ToString("yyyy-MM-dd");

navForm.SelectSingleNode("/my:meineFelder/my:CreationDay", NS).SetValue(convDate);


And it looks like a normal date field:

As you can see the red dotted validation does not show up.

..:: I like SharePoint ::..

SharePoint 2010 Using Parameters in InfoPath forms

If you would like to pass parameters into an InfoPath form, for example to call specific data into the form you can do it really easy. In my case we are using code behind, i am not sure if you can read parameters without using code, but if it is possible please let me know.

As i said you need to add code behind into your form, in order to access the parameters. Afterwords you have to insert the form loading event and use these lines of code:



public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
//Getting the Parameters from Url
string para_ticketId = string.Empty;
if(e.InputParameters.ContainsKey("ticketId"))
para_ticketId = e.InputParameters["ticketId"];

//Setting Parameter into Field of Form
XPathNavigator navForm = this.CreateNavigator();
XmlNamespaceManager NS = this.NamespaceManager;

navForm.SelectSingleNode("/my:meineFelder/my:TicketID", NS).SetValue(para_ticketId);

}


By using the e.InputParameters["yourparameter"] you can access the values of the parameter. By using the contains key you can check if the parameter is attached to the url. This is important that you don’t get an error message cause the parameter is missing. It’s better to check it by yourself and give a nice error message to the user.

Now your InfoPath form can read the parameter and write it into any field you like. If you open the InfoPath form by using this adress:

http://yourserver/sites/yourSiteCollection/_layouts/FormServer.aspx?xsnLocation=~sitecollection/FormServerTemplates/yourInfoPathForm.xsn&openin=browser&ticketId=ilikesharepoint

The InfoPath form writes this value “ilikesharepoint” into the desired field:

Hope this helps you a little bit. If you would like to know more about, i recommend you to read this great post.

..:: I LIKE SHAREPOINT ::..

SharePoint 2010 Deploy InfoPath in Visual Studio Solution with Code Behind

This post is based on my previous article in which i describe how to deploy an InfoPath form via Visual Studio Solution. Please read it first and then come back to this post cause we will use the example and add the code behind.

Ok, if you like to add code behind in your InfoPath form you normally have installed the VSTA Addin in your Office package. Afterwards you can choose which language for programming you would like to have.

After that you can add a loading event to your form.

It opens the Visual Studio Project.

Now you can deploy this project and you will find a .dll in your bin folder. Remember this. But first you publish your form again and put it into your solution again like in my previous post. (more…)