Showing posts with label Infopath. Show all posts
Showing posts with label Infopath. Show all posts

Wednesday, November 17, 2010

InfoPath form 2010-Add dropdown items dynamically

I was working on adding items to DropDown control in Infopath form, you can do this as explained below
Before doing this create datasource DataSources["options"]. with XML













private void BindCustomerDropDown()



{


try


{




DataTable dtCustomer = // Load datatable
if (dtCustomer != null && dtCustomer.Rows.Count > 0)


{


string name = string.Empty;


string id = string.Empty;


RemoveFirstItem();


foreach (DataRow row in dtCustomer.Rows)


{


if (row["CustomerName"] != null)


name = row["CustomerName"].ToString();






if (row["CustomerId"] != null)


id = row["CustomerId"].ToString();






AddItem(id, name);


}


RemoveFirstItem();


}


}


catch (System.Exception ex)


{


ShowMessage(ex.Message);


}






}






private void RemoveFirstItem()


{


XPathNavigator DOM = DataSources["options"].CreateNavigator();


if (DOM == null)


return;


XPathNavigator group1 = DOM.SelectSingleNode("//options", NamespaceManager);


if (group1 == null)


return;


XPathNavigator field1 = DOM.SelectSingleNode("//options/option", NamespaceManager);


if (field1 == null)


return;


field1.DeleteSelf();


group1.InnerXml = group1.InnerXml.Replace("\r", " ");


group1.InnerXml = group1.InnerXml.Replace("\n", " ");


}










private void AddItem(string itemId, string itemName)


{


//RemoveFirstItem();


XPathNavigator DOM = DataSources["options"].CreateNavigator();


if (DOM == null)


return;


XPathNavigator group1 = DOM.SelectSingleNode("//options", NamespaceManager);


if (group1 == null)


return;


XPathNavigator field1 = DOM.SelectSingleNode("//options/option", NamespaceManager);


if (field1 == null)


return;


XPathNavigator newNode = field1.Clone();


newNode.SelectSingleNode("value").SetValue(itemId);


newNode.SelectSingleNode("displayname").SetValue(itemName);


group1.AppendChild(newNode);


}
 
you can refer these links for more details
http://www.bizsupportonline.net/infopath2007/programmatically-fill-populate-drop-down-list-box-infopath-2007.htm
http://blogs.catapultsystems.com/sboldt/archive/2009/08/07/populating-a-list-box-in-infopath-2007-form-services-from-a-sql-stored-procedure.aspx

Wednesday, September 29, 2010

InfoPath 2010: Send Email on button click ( Custom Code)

I was searching for sending Mail from Infopath form, on click of button through custom code.

Initially I tried this by googling,

EmailAdapterObject myEmailAdapter =

((EmailAdapterObject)thisXDocument.DataAdapters["Email Submit Internal"]);
 myEmailAdapter.To = list@example.com;
 myEmailAdapter.Subject = "Status Report";
 myEmailAdapter.Submit();

But in above code, I was not able to get "thisXDocument" reference.

Then I used below code to send Email

Microsoft.Office.Interop.Outlook.Application objOutlook = new Microsoft.Office.Interop.Outlook.Application();



Microsoft.Office.Interop.Outlook.MailItem objOutlookMsg = (MailItem)objOutlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);





objOutlookMsg.To = "  To Address ";


//objOutlookMsg.CC = AddressCC;


//objOutlookMsg.BCC = AddressBCC;


objOutlookMsg.Subject = "TestMail";
objOutlookMsg.Body = "Body of email";

// If you want to attach image 

objOutlookMsg.Attachments.Add(@"\image\header.jpg", Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, objOutlookMsg.Body.Length + 1, "My Attachment");


objOutlookMsg.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal;


//objOutlookMsg.Display(true);


objOutlookMsg.Send();


objOutlook = null;
objOutlookMsg = null;

InfoPath 2010 : How to make Text fields Visible False

I was just trying to figure our, how can we make the fields visible false in Infopath designer 2010.

I didnot find any direct way, but what we can do is, while designing, create textfield, appropriate field name will get create under "MYfields". Later delete the Text field from UI, but stil you can work with the fields declared under "MyFields".

Wednesday, September 15, 2010

Infopath 2010 - Error while connecting to Web service

I was trying to populate data in Infopath form by calling webservice .

I was getting below error when I try to call webservice through code.

Request for the permission of type 'System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

After doing so many R&D, I found this can be solved by adding "Full" trust in Web.config, but in Infopath project, we won't get Web.config file. We have only App.Config file.

After searching in Infopath Form, where you can set Full Trust.

Open Infopath 2010 form in Design Mode.
Click on Langauge Tab.


Under Security and Trust - Select Full Trust option.

This will solve your problem

Monday, September 6, 2010

Error while opening Infopath file

When I was trying to open Infopath file (.xsn) , I was getting below error.

This form cannot be opened because it requires the domain permission level

Error Details:
Forms that require the domain permission level contain features
that access information on a network, such as data connections, linked images, and code.
 
The solution for this is very simple.
Right click on the file, select "Design" option. this will work