I've searched a few of the forums on here but to no avail. I have a VBA Project on Microsoft Outlook 2016, and I need to add email information to a SharePoint List. The most straight-forward solution seems to be using Visual C# to connect directly. I have downloaded the Microsoft SharePoint ISAPI web server extensions. My compiler (csc) is version 4.7.2046.0 running C# 5 (I know it's not the latest version).
using System;
using Microsoft.SharePoint.Client;
/* Run with:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /reference:"C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" /reference:"C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" add.cs
*/
namespace ConsoleApplication
{
class AddToList
{
public static void InsertEnquiryToSharepoint(string rTest, string rSubject, string rUser, DateTime rDate, string rEmail, string rPhone)
{
string siteUrl = "https://myteamsite.com/teams/teamname/";
ClientContext clientContext = new ClientContext(siteUrl);
Microsoft.SharePoint.Client.List oList = clientContext.Web.Lists.GetByTitle("ListName");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem oListItem = oList.AddItem(itemCreateInfo);
oListItem["Test"] = rTest;
oListItem["Subject"] = rSubject;
oListItem["User"] = rUser;
oListItem["DateTime"] = rDate;
oListItem["Email"] = rEmail;
oListItem["Phone"] = rPhone;
oListItem.Update();
clientContext.ExecuteQuery();
}
static void Main(string[] args)
{
InsertEnquiryToSharepoint("Yes", "A test subject", "Kevin Shelley", System.DateTime.Now, "No", "No");
}
}
}
I am running the command as a test in my command line, and since it is not coming back with any error messages, I can't debug it past execution. Here is the CL command:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /reference:"C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll" /reference:"C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" add.cs
Since I am writing the initial project in VBA and referencing this, I am willing to utilize a VBA solution that can work inside of Microsoft Outlook 2016. Thanks.
EDIT: I failed and didn't run the executable this created; However, once I did I got the following error and stack trace:
Unhandled Exception: System.Net.WebException: The remote server returned an error: (403) Forbidden.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at ConsoleApplication.AddToList.InsertEnquiryToSharepoint(String rTest,
String rSubject, String rUser, DateTime rDate, String rEmail, String rPhone)
at ConsoleApplication.AddToList.Main(String[] args)
My assumption would be that I required permissions for the site. If so, how do I go about passing credentials safely?