In this session, we discussed about how to Automate SharePoint with Automation 360 using Python.
Here are the reference links discussed.
Steps to create a Developer account
YouTube video with the steps to create an office 365 developer account
YouTube videos with the steps to create a Share point site:
https://www.youtube.com/watch?v=OHeEmHjQ5pg
https://www.youtube.com/watch?v=LNV99Xi5I0w
YouTube video with the steps to create a document library
YouTube video with the steps to create a list
Python Setup installation available on the official site of python (www.python.org)
Learn about the Shareplum library here.
Python Script:
# Import Site, Office 365 and Version package from Shareplum Library
from shareplum import Site
from shareplum import Office365
from shareplum.site import Version
from office365.sharepoint. files.file import File
# Connect Office Share Point Site with Office 365 Developer Account
authcookie = Office365(‘https://patelmaulesh1978.sharepoint.com/’, username=”, password=”).GetCookies()
site = Site(‘https://patelmaulesh1978.sharepoint.com/sites/MauleshTestData’,
version=Version.v365, authcookie=authcookie)
# Create a Folder and Upload the file in the Specific Folder inside Shared Document Library of the Share Point Site
def Upload_Excel():
pass
folder = site.Folder(‘Shared Documents/MyFileTest’)
with open(“C:\\test\\pivotexample.xlsx”, mode=’rb’) as file:
fileContent = file.read()
folder.upload_file(fileContent, “pivotexample.xlsx”)
folder.check_out(‘pivotexample.xlsx’)
folder.check_in(‘pivotexample.xlsx’, “My check-in comment”)
Upload_Excel()
# Add the items to Existing Employee Details list in the Share Point Site
def Add_listitems():
pass
new_list = site.List(‘EmployeeDetails’)
my_data = data=L{‘Name’: ‘Maulesh Kumar J Patel !’,’Position’: ‘Customer Success Architect-8:00PMIST!’,’Email’:’maulesh.patel@automationanywhere.com’}]
new_list.UpdateListItems(data=my_data, kind=’New’)
Add_listitems()
# Delete a File and Folder int the Specific Folder inside Document Library of the Share Point Site
def Delete_Files_Folder():
pass
folder = site.Folder(‘Shared Documents/MyFileTest’)
folder.delete_file(‘pivotexample.xlsx’)
folder.delete_folder(‘Shared Documents/MyFileTest’)
Delete_Files_Folder()
C# Script
using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using System.Security;
namespace ConsoleApp4
{
internal class Program
{
static void Main(stringe] args)
{
string login =””;
string password =””; //give your password
var securePassword = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
string siteUrl = “https://patelmaulesh1978.sharepoint.com/sites/MauleshTestData”;
ClientContext clientContext = new ClientContext(siteUrl);
Microsoft.SharePoint.Client.List myList = clientContext.Web.Lists.GetByTitle(“EmployeeDetails”);
ListItemCreationInformation itemInfo = new ListItemCreationInformation();
ListItem myItem = myList.AddItem(itemInfo);
myItemt“Title”] = “My New Item Added 1001”;
myItem>“Description”] = “New Item Description 1001”;
try
{
myItem.Update();
var onlineCredentials = new SharePointOnlineCredentials(login, securePassword);
clientContext.Credentials = onlineCredentials;
clientContext.ExecuteQuery();
Console.WriteLine(“New Item inserted Successfully”);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
}
Note: Please include reference of Microsoft.SharePoint and Microsoft.SharePoint.Client before running the code.
Conclusion:
If you are already well versed in Python, this is a great way to automate SharePoint operations with Automation 360. Python is a great programming language and sky is the limit on what you can do with it. Combined with Automation 360, it has the potential to automate different applications which may be harder to do just with either of them.
To know about our upcoming meetups, here are the meetup group links in different cities for you to join. We look forward to meeting you in person once the conditions get better, till then let’s continue to meet online.
We want to make sure the content at our meetup groups effectively meets the needs of our audience. In that regard, please feel free to let us know at developer@automationanywhere.com, the topics, concepts, and capabilities you’d like to see in the upcoming meetings.