Using SharePoint object model to add an new list item. All resources say the code should not have been affected in the upgrade. It builds with now errors ... deploys to the Sandbox and activates. The form opens in the browser with no error ... a critical error is thrown when at the clickedevent - This was working before the upgrade to the 15 bits. I also opened it in the InfoPath client and received the following error at the clickedevent:
Could not load file or assembly 'Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified. at RequestsV4.FormCode.SubmitEquipment_Clicked(Object sender, ClickedEventArgs e) at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)
It referenced the version 14 - This is no help - I ran this through a dev environment running SharePoint Server 2013 and InfoPath 2013 with the same disappointing result. I have also ran this against two separate Office 365 tenancies running the 15 bits.
Please help!
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using Microsoft.SharePoint;
namespace RequestsV4
{
public partial class FormCode
{
public void InternalStartup()
{
((ButtonEvent)EventManager.ControlEvents["SubmitEquipment"]).Clicked += new ClickedEventHandler(SubmitEquipment_Clicked);
}
public void SubmitEquipment_Clicked(object sender, ClickedEventArgs e)
{
// Use InfoPath OM's ServerInfo.SharePointSiteUrl property to programmatically
// specify the site where the form is published.
using (SPSite FormSite = new SPSite(ServerInfo.SharePointSiteUrl.ToString()))
{
using (SPWeb FormWeb = FormSite.OpenWeb())
{
// Get the SharePoint list.
SPList LookupList = FormWeb.Lists["RequestList"];
SPListItem NewItem = LookupList.Items.Add();
// Set the value of the Title field in the list to the value in Combo Box on the form.
NewItem["Title"] = GetDomValue("/my:myFields/my:RequestName");
// Set AllowUnsafeUpdates to 'true' to temporarily allow updates to the database.
FormWeb.AllowUnsafeUpdates = true;
NewItem.Update();
// Set AllowUnsafeUpdates back to 'false' to prevent further updates to the database.
FormWeb.AllowUnsafeUpdates = false;
}
}
}
private string GetDomValue(string XpathToGet)
{
return this.CreateNavigator().SelectSingleNode(XpathToGet, this.NamespaceManager).Value;
}
}
}