1. ATK Gimmy Susan
  2. PowerBuilder
  3. Saturday, 21 September 2019 18:53 PM UTC

 

Does anyone have successful story ( examples ) to be shared with how to integrate Powerbuilder with Microsoft sharePoint on line  ?

 

Accepted Answer
ATK Gimmy Susan Accepted Answer Pending Moderation
  1. Thursday, 26 March 2020 09:16 AM UTC
  2. PowerBuilder
  3. # Permalink

Good morning.

We solved this problem by creating a C&C class that interfaces with sharepoint DLLs ( NO REST ).

 

 

p.s.

Grazie Marco

 

Comment
  1. Armeen Mazda @Appeon
  2. Monday, 21 June 2021 15:19 PM UTC
Thanks for sharing the solution!
  1. Helpful
There are no comments made yet.
Steen Jakobsen Accepted Answer Pending Moderation
  1. Wednesday, 23 June 2021 04:30 AM UTC
  2. PowerBuilder
  3. # 1

We have done it using a c# assembly with standard CSOM and Azure API.

It works GREAT and STABLE in Pb2019R3.

 

Also we are using c# exe files that we Run()  to execute tasks in the background on legacy sp platforms 07,10,13

Tell me what you want to do and I might be able to help.

//Steen

 

 

Comment
There are no comments made yet.
Mayller Lopez Accepted Answer Pending Moderation
  1. Monday, 21 June 2021 11:55 AM UTC
  2. PowerBuilder
  3. # 2

Good morning.

We solved this problem by creating a C&C class that interfaces with sharepoint DLLs ( NO REST ).

 

 

p.s.

Grazie Marco

 

Hi, do you mind sharing the method you use? Thanks

Comment
  1. Gimmy Susan
  2. Monday, 21 June 2021 13:02 PM UTC
It is something like this:



















==== My SharePoint.cs ====



using System;

using System.IO;

using System.Security;

using Microsoft.SharePoint.Client;



namespace Ateikon.ProgenAM.Coge.SharePoint

{

public class ProgenAMLog

{

private string _username;

private string _password;

private string _RaccoltaDocumenti;

private string _siteUrl;

SharePointOnlineCredentials _credentials;

ClientContext _ctx;



public void init(string username, string password, string siteUrl, string RaccoltaDocumenti)

{

_username = username;

_password = password;

_siteUrl = @siteUrl;

_RaccoltaDocumenti = @RaccoltaDocumenti;



SecureString securepass = new SecureString();

foreach (char ch in password.ToCharArray())

securepass.AppendChar(ch);



_credentials = new SharePointOnlineCredentials(_username, securepass);



_ctx = new ClientContext(_siteUrl);

_ctx.Credentials = _credentials;

}



public string dirlist()

{

string items = "";



using (_ctx)

{

List spLib = _ctx.Web.Lists.GetByTitle(_RaccoltaDocumenti);



_ctx.Load(spLib);

_ctx.Load(spLib.RootFolder);

_ctx.Load(spLib.RootFolder.Folders);

_ctx.Load(spLib.RootFolder.Files);

_ctx.ExecuteQuery();

FolderCollection fcol = spLib.RootFolder.Folders;

FileCollection ficol = spLib.RootFolder.Files;



// visualizzo FILES

foreach (Microsoft.SharePoint.Client.File fi in ficol)

items += fi.Name + ",";

// visualizzo CARTELLE

//foreach (Folder f in fcol)

// items += f.Name + ",";

}



return items;

}



public void upload(string filePath)

{

string filepath = @filePath;

string fileName = filepath.Substring(filepath.LastIndexOf("\\") + 1);



byte[] content = System.IO.File.ReadAllBytes(filepath);



const int UPLOAD_SIZE_LIMIT = 1048576; //2 MB dimensione massima del messaggio di upload, considerando dati nome file ecc, mi tengo un margine di sicurezza e lo abbasso a 1MB ... gia con 1,5MB dava errore di messaggio troppo lungo



// creo il contesto client sharepoint

using (_ctx)

{

// creo l'oggetto per l'upload del file

FileCreationInformation fcInfo = new FileCreationInformation();

//fi.Url = destinationPath + "/" + filePath;

fcInfo.Url = fileName;

fcInfo.Overwrite = true;



// file da uploadare

if (content.LongLength > UPLOAD_SIZE_LIMIT)

fcInfo.Content = new byte[1]; // se il file è troppo grande salvo uno file fittizio, quello reale verrà caricato dopo

else

fcInfo.Content = content; // altrimenti salvo il file <= 1MB



//aggiungo il file alla folder (messaggio totale max 2MB)

List spLib = _ctx.Web.Lists.GetByTitle(_RaccoltaDocumenti);

Microsoft.SharePoint.Client.File fileNew = spLib.RootFolder.Files.Add(fcInfo);

//leggo il server relative path del nuovo file

_ctx.Load(fileNew, x => x.ServerRelativeUrl);



//aggiorno le proprietà

ListItem item = fileNew.ListItemAllFields;

item["Title"] = fileName;

item.Update();

_ctx.Load(item);



// esegui i comandi caricati nel contesto -> salvo il file

_ctx.ExecuteQuery();



if (content.LongLength > UPLOAD_SIZE_LIMIT)

{

//per superare i problemi di upload con grossi file uso SaveBinaryDirect https://msdn.microsoft.com/en-us/pnp_articles/upload-large-files-sample-app-for-sharepoint

using (System.IO.MemoryStream fs = new System.IO.MemoryStream(content))

{

Microsoft.SharePoint.Client.File.SaveBinaryDirect(_ctx, fileNew.ServerRelativeUrl, fs, true);

}

}

}

}



public void download(string filename, string localdir)

{

using (_ctx)

{

var spLib = _ctx.Web.Lists.GetByTitle(_RaccoltaDocumenti);

_ctx.Load(spLib.RootFolder);

_ctx.ExecuteQuery();



var targetFileUrl = string.Format("{0}/{1}", spLib.RootFolder.ServerRelativeUrl, System.IO.Path.GetFileName(filename));

var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(_ctx, targetFileUrl);



var localFile = System.IO.Path.Combine(localdir, System.IO.Path.GetFileName(targetFileUrl));

using (var filestream = System.IO.File.Create(localFile))

{

fileInfo.Stream.CopyTo(filestream);

}

}

}



public void delete(string filename)

{

using (_ctx)

{

List spLib = _ctx.Web.Lists.GetByTitle(_RaccoltaDocumenti);

_ctx.Load(spLib.RootFolder);

_ctx.ExecuteQuery();



var targetFileUrl = string.Format("{0}/{1}", spLib.RootFolder.ServerRelativeUrl, System.IO.Path.GetFileName(filename));

Microsoft.SharePoint.Client.File file = _ctx.Web.GetFileByServerRelativeUrl(targetFileUrl);



//Microsoft.SharePoint.Client.File file = _ctx.Web.GetFileByServerRelativeUrl("/sites/SPI/Documenti%20condivisi/csharp2pb.dll");

_ctx.Load(file, f => f.Exists);

file.DeleteObject();

_ctx.ExecuteQuery();

}

}



public void copioilfile()

{

string filename = @"c:\temp\gimmy.txt";

FileInfo filoc = new FileInfo(filename);

string destinationfile = @"c:\temp\gimmy2.txt";

filoc.CopyTo(destinationfile, true);

}

}

}

  1. Helpful
  1. Mayller Lopez
  2. Wednesday, 23 June 2021 04:20 AM UTC
Thank you Gimmy, btw would this work in PB12.6 classic? Or will it only work on a higher version?
  1. Helpful
  1. Gimmy Susan
  2. Wednesday, 23 June 2021 16:30 PM UTC
i use it with pb2019Rx, but i suppose, with a wrapper, it is possible to use the old version of pb
  1. Helpful
There are no comments made yet.
Marco Meoni Accepted Answer Pending Moderation
  1. Monday, 23 September 2019 11:45 AM UTC
  2. PowerBuilder
  3. # 3

Hi Gimmy,
CoderObject and HttpClient already provide all the necessary for authenticating against SharePoint and perform operations, for example get items and upload files.


A mockup for authentication:

// Build authorization in Base64
ls_auth = coderObject.Base64Encode(Blob("username:password", EncodingANSI!))

// Set headers
httpClient.SetRequestHeader("Authorization", "Basic " + ls_auth)
httpClient.SetRequestHeader("Accept","application/json")
// etc....

// Send authentication request (check your SP URL)
li_rc = httpClient.SendRequest("POST", "http://sharepoint_server/sites/doc/_api/contextinfo")

// obtain the response data 
if li_rc = 1 AND inv_HttpClient.GetResponseStatusCode() = 200 Then
   // GetResponseBody and parse Json to get, for example, GetContextWebInformation, FormDigestValue, etc...

 

If you want to get SP's items, send a GET to http://sharepoint_server/sites/doc/_api/lists

If you want to upload files, send POST to SP's folder, e.g. http://sharepoint_server/sites/doc/prev/cf/_api/web/lists/getbytitle

and so on...

Best,

.m

Comment
  1. ATK Gimmy Susan
  2. Tuesday, 24 September 2019 11:06 AM UTC
Hi Marco

Ty for answer



Unfortunately we are not familiar with CoderObject and HttpClient.

I'm looking for working examples for understand and implement

=)
  1. Helpful
  1. Kevin Ridley
  2. Monday, 21 June 2021 12:04 PM UTC
Don't be afraid to learn something new. REST is the current industry standard and is quite a bit easier than analyzing the Sharepoint DLL and creating a C# wrapper class. You will probably encounter many more situations where REST will come in handy for you to interface with other sources. Why not keep your app pure Powerbuilder as well? Now you've got another codebase in another language that you will need to maintain. Glad you got it working though.
  1. Helpful
There are no comments made yet.
Aron Cox Accepted Answer Pending Moderation
  1. Monday, 23 September 2019 07:38 AM UTC
  2. PowerBuilder
  3. # 4

I created a .NET COM dll that did all the SharePoint stuff I needed and then called that from PowerBuilder. There appears to be multiple ways to access SharePoint and I picked the SharePoint client object model.

Examples of how to call it can be found here: https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-client-library-code

This has a walkthrough of creating a SharePoint project in Visual Studio: https://www.c-sharpcorner.com/article/sharepoint-client-object-modal-csom/ which would be a good place to start

Then it's just a matter of deciding what you need to do, how the SharePoint site is organised, and how to make your .NET dll in a COM object that can be called by PowerBuilder. We can help you with that here is that's the route you decide to go.

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Saturday, 21 September 2019 23:45 PM UTC
  2. PowerBuilder
  3. # 5

Hi Gimmy;

  FYI: PB PT Integration

Regards ... Chris

Comment
  1. ATK Gimmy Susan
  2. Monday, 23 September 2019 08:50 AM UTC
too expensive for my project
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Saturday, 21 September 2019 23:27 PM UTC
  2. PowerBuilder
  3. # 6
Comment
  1. ATK Gimmy Susan
  2. Monday, 23 September 2019 08:50 AM UTC
too expensive for my project
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.