Archive | InfoPath 2010 RSS for this section

Show/Display Multiple InfoPath Views using InfoPath Form Web Part in SharePoint 2010

Hey Folks!!

I guess I have already answered your question (if you have searched it on search engines 😛 )

That is, How To Show/Display Multiple InfoPath Views?

A little bit of background, I had a requirement where I need to create an InfoPath form with some data.

The catch was, I should create two views, Manager & Employee, and I needed to show the multiple views with direct link to the page.

Usually, you can right click on model dialog page where InfoPath forms opens, right click & copy the URL and directly assign it the way you like it.

But the problem is the InfoPath form will show the tab to switch between the views, also I didn’t wanted the users to switch to the views anyhow.

So, the answer is to use InfoPath Form Web Part

To be continued….

Forms that require the domain permission level contain features that access information on a network, such as data connections, linked images, and code

This was really strange (but funny) issue!!

I created few of the InfoPath Forms and published them into the SharePoint 2010 Library.

After a while, I got a request from another Developer asking me for the forms as they wanted to update and make few changes into the existing form. (So I did give them the forms 😛 )

After a while they come running to me and said that they are getting an error while opening the form and below is the error:

“This form cannot be opened because it requires the domain permission level and it currently has restricted permission.”

And another error:

“Forms that require the domain permission level contain features that access information on a network, such as data connections, linked images, and code.”

InfoPath Error

Strange!!

Can’t a developer just edit the InfoPath form of an another Developer?!?!

I asked the developer to send me the list of steps he is following while trying to open the file (and that’s the catch).

What he was trying is “Double-click on the form to open it?!?!?!?!”

Solution: Right Click on the form and Select “Design” 🙂

Have fun & Enjoy!!

How To : Calculate Median Value Using InfoPath Forms

Thanks To Entan Ming!!

I was going crazy for this untill Entan Ming provided a solution to me.

I wanted to calculate Median for values entered into my InfoPath form (as of now I have provided 10 textboxes in InfoPath but you can modify my code as per your requirement)

Though I have provided 10 textboxes, users can enter less than 10 values as well and I need to count Median for it.

Yes, I know that we can achieve this simply by creating a List with one calculated column and can use =MEDIAN() formula (as simple as that)

But when users want to see the final Median value before submitting the values (for whatsoever reason), you can’t use List!!

So, Let’s start!!

First of all (if you are not aware of how to do it), check out my post on How To : Code in InfoPath Forms 2010

Once you know what I am talking about (for this perticular code), create 11 textboxes and 1 button and call below method on button click:

Code:

public void sorting()

{

int[] arry = new int[11];
int counter = 0;

for (int i = 1; i <= 10; i++)
{
if (MainDataSource.CreateNavigator().SelectSingleNode(“/my:myFields/my:field” + i + “”, NamespaceManager).Value != “”)
{
arry[i] = Convert.ToInt32(MainDataSource.CreateNavigator().SelectSingleNode(“/my:myFields/my:field” + i + “”, NamespaceManager).Value);
counter++;
}
else
{
break;
}
}

int[] resul = new int[counter];
for (int i = 0; i < counter; i++)
{
resul[i] = arry[i + 1];
}

bool sortnum = true;

int pos = 0;

int tot = counter;

int median = 0;

while (sortnum == true)
{

for (int j = (pos + 1); j < tot; j++)
{

int rd = resul[pos];

int fg = resul[j];

if (rd > fg)
{

resul[pos] = fg;

resul[j] = rd;

}

}

pos = pos + 1;

if (pos >= tot)
{

sortnum = false;

}

}

if (tot % 2 == 0)
{

int sdd = resul[(tot / 2) – 1] + resul[tot / 2] / 2;

median = sdd;

}

else
{

median = resul[(tot – 1) / 2];

}

string a = Convert.ToString(median);

XPathNavigator P2 = this.MainDataSource.CreateNavigator().SelectSingleNode(“//my:myFields/my:field11”, this.NamespaceManager);

P2.SetValue(((Convert.ToDouble(resul[(tot/2)-1]) + Convert.ToDouble(resul[(tot / 2)])) / 2).ToString());

}

You will get Median value (at run time) in your field11 textbox!! 🙂

How To : Code in InfoPath Forms 2010

Hey Folks,

Le’ts learn little bit of InfoPath today!! 🙂

I will post the basic steps to learn InfoPath later, but today I am going to show how you can Code in InfoPath.

Before we start, make sure you have installed the prerequisites:

1.  Microsoft InfoPath 2010

2.  Microsoft Visual Studio 2010

3.  Visual Studio Tools for Applications (VSTA)

So Let’s Start:

Open up InfoPath 2010 (Hope you know how to do it!! 😛 )

Go To File -> New -> Select Blank Form

Your new Blank Form will look like below, check out the demo as shown below:

Change the lable to This is a “Hellow World” InfoPath Form and add a Button control to the form:

Your form will now look like this:

Now Select Develop Tab and click on Language:

Select Category as Programming (if not selected) and choose your preferred programming language:

Click OK and close the form.

Now click on Code Editor Button in the Ribbon.

If your prerequisites were installed correctly, InfoPath forms designer will now open Visual Studio Tools for Applications and create a event handler for the button click event.

public void CTRL1_5_Clicked(object sender, ClickedEventArgs e)
{
}

Add your custom code inside this event.

public void CTRL1_5_Clicked(object sender, ClickedEventArgs e)

{

    XPathNavigator domNav = MainDataSource.CreateNavigator();
    XPathNavigator field = domNav.SelectSingleNode(“/my:myFields/my:field1”, NamespaceManager);
    field.SetValue(“Hello World”);

}

Build your code and save the project.

Return to the InfoPath Forms Designer.

On the Home pane in the ribbon you will see on the far right the form preview command.

Click on this command to preview your form.

%d bloggers like this: