Code behind button works in Infopath with VSTA but not in browser - InfoPath Dev Sign in | Join | Help in Browser Forms InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Browser Forms » Code behind button works in Infopath with VSTA but not in browser Code behind button works in Infopath with VSTA but not in browser Last post 12-16-2009 10:47 PM by Qazi Anis. 7 replies. Page 1 of 1 (8 items) Sort Posts: Oldest to newest Newest to oldest Previous Next 12-02-2009 05:52 AM Sean Sharepoint Joined on 12-02-2009 Posts 11 Code behind button works in Infopath with VSTA but not in browser Reply Contact I have an Infopath browser-enabled form where after information is entered, and a button control is clicked, 2 emails are sent and the form switches to its second view. The form works when debugged in VSTA, the emails are sent, and the form switches to its second view. Because there is code behind the form, the security level was set to Full Trust, signed with a certificate, and uploaded to Sharepoint via Central Administration. Though in Sharepoint, the form opens in Form Services, and when I click the button, a little pop up window says "Sending data to server" but the emails are never sent and the form doesnt switch to its second view. What gives? Filed under: Code behind button works in Infopath with VSTA but not in browser 12-02-2009 06:25 AM In reply to Patrick Halstead Joined on 08-08-2006 Posts 5,112 Re: Code behind button works in Infopath with VSTA but not in browser Mark as Not AnswerMark as Answer... Reply Contact Have you configured server-side emails? Patrick HalsteadProject Manager at Qdabra 12-02-2009 06:31 AM In reply to Qazi Anis Joined on 03-13-2009 Chicago Posts 1,025 Re: Code behind button works in Infopath with VSTA but not in browser Mark as Not AnswerMark as Answer... Reply Contact it seems that you are using some code that is avaiable for infopath client only like this.save(). i would suggest you paste your code here and let us have a look at it Qazi AnisTechnical ArchitectBitwise Inc 12-04-2009 06:28 AM In reply to Sean Sharepoint Joined on 12-02-2009 Posts 11 Re: Code behind button works in Infopath with VSTA but not in browser Mark as Not AnswerMark as Answer... Reply Contact This is the formcode.cs file , below it is the code for a class file that sends the emails. There are a couple other code files used if you need those let me know. Like said before, this code sends two emails and switches from the first view to the second. It was published to sharepoint, where alerts are working, so if I'm understanding your question clearly, yes emails can be sent from that server. Thanks guy for taking a look. using Microsoft.Office.InfoPath; using System; using System.Xml; using System.Xml.XPath; using RG.SalesLead; using System.Web.UI.HtmlControls; using System.Web;namespace SubmitLead { public partial class FormCode { // Member variables are not supported in browser-enabled forms. // Instead, write and read these values from the FormState // dictionary using code such as the following: // // private object _memberVariable // { // get // { // return FormState["_memberVariable"]; // } // set // { // FormState["_memberVariable"] = value; // } // } // NOTE: The following procedure is required by Microsoft Office InfoPath. // It can be modified using Microsoft Office InfoPath.public void InternalStartup() {((ButtonEvent)EventManager.ControlEvents["CTRL1_5"]).Clicked += new ClickedEventHandler(CTRL1_5_Clicked);((ButtonEvent)EventManager.ControlEvents["CTRL3_8"]).Clicked += new ClickedEventHandler(CTRL3_8_Clicked); }private void MessageBox_Show(string message) { XPathNavigator root = this.MainDataSource.CreateNavigator();string thisViewName = this.CurrentView.ViewInfo.Name; root.SelectSingleNode("/my:LeadInformation/my:ViewSender", NamespaceManager).SetValue(thisViewName);root.SelectSingleNode("/my:LeadInformation/my:SendSuccess", NamespaceManager).SetValue(message); } public void CTRL1_5_Clicked(object sender, ClickedEventArgs e) { try {RGSalesLeadData data = new RGSalesLeadData(); data.MailServer = Properties.Settings.Default.MailServerName;data.SalesForceLeadUrl = Properties.Settings.Default.SalesForceUrl; data.SalesForceOwnerID = Properties.Settings.Default.SalesForceOwnerID;data.PortalName = Properties.Settings.Default.PortalName; data.SubmitterEmail = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:CurrentUser", NamespaceManager).Value + "@robbinsgioia.com"; data.TargetLeadEmail = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:CurrentUser", NamespaceManager).Value + "@robbinsgioia.com"; data.SubmitterName = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:DisplayName", NamespaceManager).Value;data.SystemEmail = Properties.Settings.Default.SystemEmail; data.LeadTitle = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Title", NamespaceManager).Value;data.LeadFirstName = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:FirstName", NamespaceManager).Value; data.LeadLastName = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:LastName", NamespaceManager).Value;data.LeadCompany = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Company", NamespaceManager).Value; data.LeadWebsite = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Website", NamespaceManager).Value;data.LeadEmail = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Email", NamespaceManager).Value; data.LeadPhone = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Phone", NamespaceManager).Value;data.LeadFax = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Fax", NamespaceManager).Value; data.LeadMobilePhone = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:MobilePhone", NamespaceManager).Value;data.LeadDescription = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Description", NamespaceManager).Value; data.LeadAddress = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Address", NamespaceManager).Value;data.LeadCity = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:City", NamespaceManager).Value; data.LeadState = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:State", NamespaceManager).Value;data.LeadZipCode = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Zip", NamespaceManager).Value; data.LeadCountry = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Country", NamespaceManager).Value;data.LeadSource = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:LeadSource", NamespaceManager).Value; data.LeadIndustry = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Industry", NamespaceManager).Value;data.LeadRating = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Rating", NamespaceManager).Value; data.LeadEmployees = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:AnnualRevenue", NamespaceManager).Value;data.LeadAnnualRevenue = MainDataSource.CreateNavigator().SelectSingleNode("/my:LeadInformation/my:Employees", NamespaceManager).Value;data.RedirectUrl = Properties.Settings.Default.RedirectUrl; RGSalesLead sl = new RGSalesLead("Sean"); sl.Send(data); ViewInfos.SwitchView("SendSuccess"); // HttpContext.Current.Response.Redirect("http://intranet.robbinsgioia.com/default.aspx", false); }catch (System.Exception ex) { //MessageBox.Show("Failed to send" + ex.Message); } finally { } } public void CTRL3_8_Clicked(object sender, ClickedEventArgs e) { // HttpContext.Current.Response.Redirect("http://intranet.robbinsgioia.com/default.aspx", false); } } } using System.Linq; using System.Text; using System.Net.Mail; using System.Xml.XPath; using System.Xml;namespace RG.SalesLead { /// <summary> /// Manages sending leads to salesforce and other users. /// </summary> public class RGSalesLead {private string _userName = string.Empty;public RGSalesLead(string userName) {this._userName = userName; } /// <summary> /// Sends the specified send to sales forc. /// </summary> /// <param name="sendToSalesForc">if set to <c>true</c> [send to sales forc].</param> /// <param name="data">The data.</param>public void Send(RGSalesLeadData data) {StringBuilder sbBody = new StringBuilder(); sbBody.AppendFormat("<span style='font-weight:bold;font-family:verdana,tahoma,arial;font-size:11px;'>This is an automated sales lead notification from the {0}.</span><br><br>",(data.PortalName));sbBody.AppendFormat("<table cellpadding='2' cellspacing='0' style='font-family:verdana,tahoma,arial;font-size:11px;width:500px;'>"); sbBody.AppendFormat("<tr><td colspan='2' style='font-weight:bold;border-bottom:1px solid silver;'>Contact Information</td></tr>");sbBody.AppendFormat("<tr><td width='75' nowrap valign='top'><strong>Name:</strong></td><td valign='top'>{0} {1} {2}</td></tr>", (data.Salutation), (data.LeadFirstName), (data.LeadLastName)); sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Title:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadTitle));sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Email:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadEmail)); sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Phone:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadPhone));sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Fax:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadFax)); sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Mobile:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadMobilePhone));sbBody.AppendFormat("<tr><td> </td></tr>"); sbBody.AppendFormat("<tr><td colspan='2' style='font-weight:bold;border-bottom:1px solid silver;'>Company Information</td></tr>");sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Name:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadCompany)); sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Website:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadWebsite));sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Address:</strong></td><td valign='top'>{0}<br>{1} {2}, {3}<br>{4}</td></tr>", (data.LeadAddress), (data.LeadCity), (data.LeadState), (data.LeadZipCode), (data.LeadCountry)); sbBody.AppendFormat("<tr><td> </td></tr>");sbBody.AppendFormat("<tr><td colspan='2' style='font-weight:bold;border-bottom:1px solid silver;'>Lead Information</td></tr>"); sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Company Revenue:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadAnnualRevenue));sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Company Employees:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadEmployees)); sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Lead Description:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadDescription));sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Lead Source:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadSource)); sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Industry:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadIndustry));sbBody.AppendFormat("<tr><td nowrap valign='top'><strong>Rating:</strong></td><td valign='top'>{0}</td></tr>", (data.LeadRating)); //create confirmation emailStringBuilder sbUserBody = new StringBuilder(); sbUserBody.AppendFormat("<span style='font-family:verdana,tahoma,arial;font-size:11px;'> {0},</span><br><br>", data.SubmitterName);sbUserBody.Append("<span style='font-family:verdana,tahoma,arial;font-size:11px;'>We have received your sales lead and will contact you for more information if necessary.<br><br>"); sbUserBody.Append("<span style='font-family:verdana,tahoma,arial;font-size:11px;'>Thank you,<br><br>");sbUserBody.Append("<span style='font-family:verdana,tahoma,arial;font-size:11px;'>Sales");sbUserBody.Append("</span>"); // send to leadMailMessage msg = new MailMessage(data.SubmitterEmail, data.TargetLeadEmail);msg.Subject = "SalesForce Submission"; msg.Body = sbBody.ToString();msg.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(data.MailServer); smtp.Send(msg); // send confirmation to userMailMessage conf = new MailMessage(data.SystemEmail, data.TargetLeadEmail);conf.Subject = "SalesForce Submission Confirmation"; conf.Body = sbUserBody.ToString();conf.IsBodyHtml = true; smtp.Send(conf); } } } Filed under: Code behind button works in Infopath with VSTA but not in browser 12-06-2009 11:51 PM In reply to Qazi Anis Joined on 03-13-2009 Chicago Posts 1,025 Re: Code behind button works in Infopath with VSTA but not in browser Mark as Not AnswerMark as Answer... Reply Contact i guess you are not giving enough credentials for sending the mail. This will work in preview mode on infopath client but it will fail on browser. try using try catch, and in catch block do some action. like set some fields value to exception message so that you know what is happening Qazi AnisTechnical ArchitectBitwise Inc 12-07-2009 10:52 AM In reply to mrsafe Joined on 06-17-2009 Posts 31 Re: Code behind button works in Infopath with VSTA but not in browser Mark as Not AnswerMark as Answer... Reply Contact For sending the emails in a sharepoint hosted form I usually use the sendMail object in SPUtility. Using Microsoft.SharePoint.Utilities. I've never had an issues because it uses the SharePoint central emails utitlity which, if you've already set up and tested, will always send the mail. 12-16-2009 01:22 PM In reply to Sean Sharepoint Joined on 12-02-2009 Posts 11 Re: Code behind button works in Infopath with VSTA but not in browser Mark as Not AnswerMark as Answer... Reply Contact I have tried your suggestion. Form services will not let me view the field after the error occurs, it is a Critical Error, and only lets me "start over", which refreshes the form to a blank form, or "close", which redirects back to Sharepoint site. Any other ways to debug this form, I am trying to get it to write to the event logs, but have been unable to get around this error:"The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.", which I have started a thread on. Thanks verys much for your help. 12-16-2009 10:47 PM In reply to Qazi Anis Joined on 03-13-2009 Chicago Posts 1,025 Re: Code behind button works in Infopath with VSTA but not in browser Mark as Not AnswerMark as Answer... Reply Contact and after every statement you can set failed_at variable to some unique value and in the catch statement e.CancelableArgs.Message = failed_at; e.CancelableArgs.MessageDetails = exception.Message; e.CancelableArgs.Cancel = true; this way you will get the required message in the error message only Qazi AnisTechnical ArchitectBitwise Inc Page 1 of 1 (8 items) Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.
I have an Infopath browser-enabled form where after information is entered, and a button control is clicked, 2 emails are sent and the form switches to its second view. The form works when debugged in VSTA, the emails are sent, and the form switches to its second view. Because there is code behind the form, the security level was set to Full Trust, signed with a certificate, and uploaded to Sharepoint via Central Administration. Though in Sharepoint, the form opens in Form Services, and when I click the button, a little pop up window says "Sending data to server" but the emails are never sent and the form doesnt switch to its second view. What gives?
Have you configured server-side emails?
it seems that you are using some code that is avaiable for infopath client only like this.save().
i would suggest you paste your code here and let us have a look at it
This is the formcode.cs file , below it is the code for a class file that sends the emails. There are a couple other code files used if you need those let me know. Like said before, this code sends two emails and switches from the first view to the second. It was published to sharepoint, where alerts are working, so if I'm understanding your question clearly, yes emails can be sent from that server. Thanks guy for taking a look.
using
{
}
root.SelectSingleNode(
data.MailServer = Properties.
data.SalesForceOwnerID = Properties.
data.SubmitterEmail = MainDataSource.CreateNavigator().SelectSingleNode(
data.SubmitterName = MainDataSource.CreateNavigator().SelectSingleNode(
data.LeadTitle = MainDataSource.CreateNavigator().SelectSingleNode(
data.LeadLastName = MainDataSource.CreateNavigator().SelectSingleNode(
data.LeadWebsite = MainDataSource.CreateNavigator().SelectSingleNode(
data.LeadPhone = MainDataSource.CreateNavigator().SelectSingleNode(
data.LeadMobilePhone = MainDataSource.CreateNavigator().SelectSingleNode(
data.LeadAddress = MainDataSource.CreateNavigator().SelectSingleNode(
data.LeadState = MainDataSource.CreateNavigator().SelectSingleNode(
data.LeadCountry = MainDataSource.CreateNavigator().SelectSingleNode(
data.LeadIndustry = MainDataSource.CreateNavigator().SelectSingleNode(
data.LeadEmployees = MainDataSource.CreateNavigator().SelectSingleNode(
sl.Send(data);
sbBody.AppendFormat(
sbUserBody.AppendFormat(
sbUserBody.Append(
msg.Body = sbBody.ToString();
smtp.Send(msg);
conf.Body = sbUserBody.ToString();
smtp.Send(conf);
i guess you are not giving enough credentials for sending the mail. This will work in preview mode on infopath client but it will fail on browser. try using try catch, and in catch block do some action. like set some fields value to exception message so that you know what is happening
For sending the emails in a sharepoint hosted form I usually use the sendMail object in SPUtility. Using Microsoft.SharePoint.Utilities.
I've never had an issues because it uses the SharePoint central emails utitlity which, if you've already set up and tested, will always send the mail.
I have tried your suggestion. Form services will not let me view the field after the error occurs, it is a Critical Error, and only lets me "start over", which refreshes the form to a blank form, or "close", which redirects back to Sharepoint site.
Any other ways to debug this form, I am trying to get it to write to the event logs, but have been unable to get around this error:"The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.", which I have started a thread on.
Thanks verys much for your help.
and after every statement you can set failed_at variable to some unique value
and in the catch statement
e.CancelableArgs.MessageDetails = exception.Message
e.CancelableArgs.Cancel =
this way you will get the required message in the error message only