okeh, starting a new year with a tight shcedule. Once again tighting the ropes of hope towards a brighter future of sharepoint programming.
These are the new list of my work this week :
1.Search for out of range data-programmatically
2. Search on how to set background color of textbox to highlight the out of spec data
3. configure workflow to sent out emeail whenever a data is out of limit
4. create a new library to submit reports upon the out of range data from engineerss
SO
Since task number 1 is more or less done...below are the things related to task number 2... here are the things i need to know first..read read read!
Programmatically set properties on InfoPath controls
Learn why you can only use conditional formatting on controls to programmatically set properties to hide, disable, or change the color for InfoPath controls.
I’ve written about this before, but think that the topic lends itself for a repeat post, because I’ve seen many of the visitors to my site searching for answers to questions such as:
- how to hide first row by programmatically infopath
- how to change infopath textbox colour programmatically
Using conditional formatting to set properties
Whether you want to:
you have to use Conditional Formatting to do so.
- programmatically make an InfoPath control read-only
- programmatically hide an InfoPath control
- programmatically change the background color of an InfoPath control
- programmatically change the color of the text in an InfoPath control
Programming in InfoPath is different to programming in Visual Studio. InfoPath controls do not have properties you can set at run-time through code. The only properties you can set are properties that are inherent to XML nodes.
Checking the availability of properties on an InfoPath control
If you want to programmatically set a property such as Enabled, Visible, BackgroundColor, Color, ReadOnly, etc. you first have to check whether an equivalent InfoPath conditional formatting setting is available for such a property.
You can do this by:
- Double-clicking on the control to open its Properties dialog box.
- Look for a Conditional Formatting button on the Properties dialog box; it is usually located on the Display tab.
- Open the Conditional Formatting dialog box and check whether it offers a setting that you can use for the property you want to programmatically set.
Creating a hidden field to use for setting properties through code
The logic behind using a hidden field to programmatically set a property on an InfoPath control is that you have to create a condition so that the conditional formatting on the control can be activated. And one way of doing this is by programmatically setting the value of a field on which the conditional formatting depends.
And since the field you’d be using is only to manipulate the visual aspects of controls, you don’t want users to actually see this field, which is why you should make it hidden.
I thought it would be good to show you step-by-step how to implement such a solution, so have gone ahead and written an article on how to programmatically hide the first row of a repeating table in infopath. Enjoy!
UPDATE
with the help of my very skillful friends called Ms."copy all rules" and also Mr. "paste", i have now done for 2nd task... hahaha..let's proceed to the next task... :D
For the third task i'll be referring to this note. From : http://www.bizsupportonline.net/browserforms/send-email-infopath-browser-form-sharepoint.htm
How to send email from an InfoPath browser form in SharePoint
Learn which options are available for InfoPath to send email through an InfoPath form that is running in InfoPath Forms Services in SharePoint.
4 Ways to send data through email from an InfoPath form
Excluding methods which are available within SharePoint (but not within InfoPath) to send email such as sending email through an ItemAdded event handler or through a workflow, there are 4 ways to send email from an InfoPath form, which is running in InfoPath Forms Services in SharePoint:
The first 3 methods require you to install and configure an SMTP server for SharePoint. The last method only requires an SMTP server that has anonymous access enabled.
- Use Rules with an email submit data connection.
- Programmatically send an email through an EmailSubmitConnection object.
- Use the SendEmail method of the SPUtility object in SharePoint.
- Use the MailMessage and SmtpClient classes in the System.Net.Mail namespace.
All of the methods described in this article make use of an InfoPath form template that has 4 Text Box controls named toAddress, fromAddress, subject, and body, and one Button control which is used to send email.
1. Use Rules to send email in InfoPath
Add an email submit data connection named Email Submit to the InfoPath form template, and then add a Rule on the button that says:
Submit using a data connection: Email Submit
Advantages:
Disadvantages:
- You do not have to give the InfoPath form template full trust.
- You have to configure outgoing email for SharePoint.
- You cannot specify a From email address; the email address you configured for outgoing email in SharePoint will be used as the From email address.
- You cannot attach files other than the InfoPath form itself to the email.
2. Use an EmailSubmitConnection to send email in InfoPath
Add an email submit data connection named Email Submit to the InfoPath form template, and then add the following C# code to the Clicked event handler for the button:
XPathNavigator root = MainDataSource.CreateNavigator();
string toAddress = root.SelectSingleNode("//my:toAddress",
NamespaceManager).Value;
string fromAddress = root.SelectSingleNode("//my:fromAddress",
NamespaceManager).Value;
string subject = root.SelectSingleNode("//my:subject",
NamespaceManager).Value;
string body = root.SelectSingleNode("//my:body",
NamespaceManager).Value;
EmailSubmitConnection conn =
(EmailSubmitConnection)DataConnections["Email Submit"];
conn.To.SetStringValue(toAddress);
conn.Subject.SetStringValue(subject);
conn.Introduction = body;
conn.EmailAttachmentType = EmailAttachmentType.None;
conn.Execute();
Advantages:
Disadvantages:
- You do not have to give the InfoPath form template full trust.
- You have to configure outgoing email for SharePoint.
- You cannot specify a From email address; the email address you configured for outgoing email in SharePoint will be used as the From email address.
- You cannot attach files other than the InfoPath form itself to the email.
3. Use SPUtility.SendMail to send email in InfoPath
Add a reference to the SharePoint DLL to your InfoPath form template project and then add the following using statements to the FormCode.cs file:
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
Add the following C# code to the Clicked event handler for the button:
XPathNavigator root = MainDataSource.CreateNavigator();
string toAddress = root.SelectSingleNode("//my:toAddress",
NamespaceManager).Value;
string fromAddress = root.SelectSingleNode("//my:fromAddress",
NamespaceManager).Value;
string subject = root.SelectSingleNode("//my:subject",
NamespaceManager).Value;
string body = root.SelectSingleNode("//my:body",
NamespaceManager).Value;
SPWeb web = SPContext.Current.Web;
bool result = SPUtility.SendEmail(
web, false, false, toAddress, subject, body);
Disadvantages:
- You must give the InfoPath form template full trust and sign it with a digital certificate.
- You have to configure outgoing email for SharePoint.
- You cannot specify a From email address; the email address you configured for outgoing email in SharePoint will be used as the From email address.
- You cannot attach files to the email.
4. Use System.Net.Mail classes to send email in InfoPath
Add the following using statement to the FormCode.cs file:
using System.Net.Mail;
Add the following C# code to the Clicked event handler for the button:
XPathNavigator root = MainDataSource.CreateNavigator();
string toAddress = root.SelectSingleNode("//my:toAddress",
NamespaceManager).Value;
string fromAddress = root.SelectSingleNode("//my:fromAddress",
NamespaceManager).Value;
string subject = root.SelectSingleNode("//my:subject",
NamespaceManager).Value;
string body = root.SelectSingleNode("//my:body",
NamespaceManager).Value;
using (MailMessage msg = new MailMessage(fromAddress, toAddress))
{
msg.Subject = subject;
msg.Body = body;
msg.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient("<your_smtp_server_name>");
smtp.Send(msg);
}
Advantages:
Disadvantages:
- You do not have to configure outgoing email for SharePoint.
- You can specify a From email address.
- You can attach files other than the InfoPath form to the email.
- You must give the InfoPath form template full trust and sign it with a digital certificate.
Conclusion
You can use Rules, an EmailSubmitConnection, the SPUtility.SendEmail method, or classes in the System.Net.Mail namespace to submit or send email in InfoPath, but only the last method provides you with total control over the From email address and email attachments.
The method you choose to use InfoPath to send email will depend largely on whether you want to or can write code or not, what you would like to include in emails you send, and whether you require to include attachments and/or have control over the From email address.
Related InfoPath Articles:
i'll be using 2nd way. In which i want to attach the form in the email. So, in the code line :
conn.EmailAttachmentType = EmailAttachmentType.None;
I'll change none to Xml. Why? This is the explanation from msdn :
Set to EmailAttachmentType.Xml to send only the form file (.xml). Set to EmailAttachmentType.XmlXsn to send the form file (.xml) along with its associated form template file (.xsn).but then, i got this error : "KeyNotFoundException" . Through googling session i found this workaround :
adehhh but then...i don't understand the instruction..kih kih kihError message when you try to debug an InfoPath form project that is built by using VSTO or VSTA: "System.Collections.Generic.KeyNotFoundException"
SYMPTOMS
When you try to debug and test an InfoPath form project that contains command line arguments, you receive the following error message:You receive the error message if the InfoPath form project is built by using Microsoft Visual Studio Tools for Office System (VSTO) or Microsoft Visual Studio Tools for Applications (VSTA).System.Collections.Generic.KeyNotFoundException
The given key was not present in the dictionary.WORKAROUND
VSTO
To work around this issue in a VSTO project, follow these steps:
- In Visual Studio, click ProjectName Properties on the Project menu, and then click Debug.
- In the Start Action section, select Start external program, and then locate the Infopath.exe file.
- In the Start Options section, type the following in the Command line arguments box:
/preview "Path\manifest.xsf" /sampledata "Path\template.xml" /viewname "View 1" /inputparameters "Parameter"Note The view name may not be "View 1." You must verify the view name in the project.
Parameter is the placeholder for the parameter that you want to pass.- Press F5 to debug the project.
VSTA
To work around this issue in a VSTA project, follow these steps:
- Create a new XML file that is based on the InfoPath form template. The InfoPath form template is an .xsn file.
- Save the XML file as Test.xml.
- Click Start, click Run, type InfoPath "Path\Test.xml" /inputparameters "Parameter" in the Open box, and then click OK.
No comments:
Post a Comment