0
votes

Using data connection in SharePoint 2013, or any other method, is it possible to submit form data with each form completion to an external landing place, like a list in SharePoint 365 online? I am new to SharePoint and am needing to learn the ropes pretty quick! Thanks for any help you can provide.

Have a great 2020!

2

2 Answers

0
votes

You could develop a custom WebPart or Add-in for SP 2013 and in c# code of this project You could, using SPOnline CSOM, add items to SP Online.

The main problem is the authentication model You are using in SP-OnPrem and SP-online (OF365 tenant). If You have the same kind of authorization provider (for example in both places You are using adfs) then there should not be much of a problem to (as the same user account) submit some data from OnPrem to Online with some Add-in or Webpart as the user will be authenticated in both places. Otherwise You can submit some data from OnPrem to Online with CSOM but You will need to login (in code.. like hardcoded) as some user. This is not the best option from security point of view.

Here is an example how to login to SP Online using CSOM (You could do something very similar in the webpart or Add-in).

... so this are only ideas but generally to do this kind of logic first You need to figure out how You authenticate between OnPrem and Online. If You authenticate the 'same way' You could just create the context of SPOnline and then add/delete or update items with the user permissions. Otherwise You need to authenticate to SPOnline as some user to submit data.

0
votes

If you use the OOTB list form, we can create an event receivers and use CSOM C# code to add new item to SharePoint Online list. The following code for your reference.

using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using System.Security;
using Microsoft.SharePoint.Client;

namespace SharePointProjectER.CustomListER
{
    /// <summary>
    /// List Item Events
    /// </summary>
    public class CustomListER : SPItemEventReceiver
    {

        /// <summary>
        /// An item was added.
        /// </summary>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            base.ItemAdded(properties);
            if (properties.List.Title == "CL0106")
            {
                //add item to SharePoint Online list
                string siteUrl = "https://tenant.sharepoint.com/sites/team";
                string userName = "[email protected]";
                string password = "xxx";

                var securePassword = new SecureString();
                foreach (char c in password.ToCharArray()) securePassword.AppendChar(c);
                var credential = new SharePointOnlineCredentials(userName, securePassword);
                ClientContext clientContext = new ClientContext(siteUrl);
                clientContext.Credentials = credential;
                List oList = clientContext.Web.Lists.GetByTitle("CL0106");

                ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                ListItem oListItem = oList.AddItem(itemCreateInfo);
                oListItem["Title"] = properties.ListItem["Title"];
                oListItem.Update();
                clientContext.ExecuteQuery();
            }
        }

    }
}

Or we can create a custom web part with custom form or add-in as Adam's reply, and use the CSOM C# code to achieve it.

Reference: Complete basic operations using SharePoint client library code