0

I'm trying to build a script for uploading a single file to my SharePoint storage. I'm also limited of use of official API provided by Microsoft as on my work account I'm unable to register an app.

My initial idea was to use a shareplum python module which supposedly would accept my user credentials to access the SharePoint server. This however didn't work as the script failed to reach login page. (Not entirely sure why. Supposedly due to company firewall. Will try to investigate yet.)

This led to other idea. Maybe it is possible to record particular HTTP communication to avoid using API directly and make a script that could be reused with uploaded file path as the only inputted variable?

If anyone considers this manageable, shall I use Wireshark or Postman for this? Also would highly appreciate any detailed step up guide, as I'm poorly experienced in this area.

Thanks

P.S.
Uploaded files are small HTML files for test resports.

  • Are you able to request an application id to use the API from your admin? Any HTTP methods are going to be via the API, either from an SDK written in something like python, or via http directly against their REST endpoint(s) – C.Nivs Aug 28 '23 at 20:38

1 Answers1

0

You can upload files to sharepoint by csom. Please refer to following code

public static void UploadFile(ClientContext context,string uploadFolderUrl, string uploadFilePath)  
{  
    var fileCreationInfo = new FileCreationInformation  
    {  
            Content = System.IO.File.ReadAllBytes(uploadFilePath),  
            Overwrite = true,  
            Url = Path.GetFileName(uploadFilePath)  
    };  
    var targetFolder = context.Web.GetFolderByServerRelativeUrl(uploadFolderUrl);  
    var uploadFile = targetFolder.Files.Add(fileCreationInfo);  
    context.Load(uploadFile);  
    context.ExecuteQuery();  
}  
  
using (var ctx = new ClientContext(webUri))  
{  
     ctx.Credentials = credentials;  
  
     UploadFile(ctx,"LibName/FolderName/Sub Folder Name/Sub Sub Folder Name/Sub Sub Sub Folder Name",filePath);     
}