//The purpose of this code is to take the attachment from an infopath form and add it to a Sharepoint 2013 library.
//I have the code below but am receiving the error "namespace Sharepoint does not exist. Even though I have added it to the references.
I believe it is because I am using the server object model even though the machine is not a server. I tried to convert the code to the client model but am still getting errors. E.g. I change SPSite to Site.
I also receive the warning: Warning 13 The primary reference "Microsoft.SharePoint" could not be resolved because it has an indirect dependency on the framework assembly "System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "Microsoft.SharePoint" or retarget your application to a framework version which contains "System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets 1605 5 Form2
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.site;
namespace Form2
{
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 InfoPath.
// It can be modified using Microsoft InfoPath.
public void InternalStartup()
{
((ButtonEvent)EventManager.ControlEvents["CTRL1_5"]).Clicked += new ClickedEventHandler(CTRL1_5_Clicked);
}
public void CTRL1_5_Clicked(object sender, ClickedEventArgs e)
{
// Retrieve the value of the attachment in the InfoPath form
XPathNavigator ipFormNav = MainDataSource.CreateNavigator();
XPathNavigator nodeNav = ipFormNav.SelectSingleNode("my:document", NamespaceManager);
string attachmentValue = string.Empty;
if (nodeNav != null && !String.IsNullOrEmpty(nodeNav.Value))
{
attachmentValue = nodeNav.Value;
// Add the file to a document library
using (Site site = new Site("https://foxgroupinc.sharepoint.com/sites/FIC-Teamsites/finance/EU/RegionalProcesses/_layouts/15/start.aspx#/Submissions%202/Forms/AllItems.aspx"))
{
using (web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
Folder docLib = web.Folders["Submissions"];
docLib.Files.Add(Name, data);
web.AllowUnsafeUpdates = false;
web.Close();
}
site.Close();
}
}
}
}
}