12Knocksinna / Office365itpros

Office 365 for IT Pros PowerShell examples

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception calling "Substring" with "2" argument(s): "Length cannot be less than zero.

stefanopagliuca opened this issue · comments

Hi, I have the following error
image
All the permission in MSGRaph seems to be correct.
Regards.

Are your SharePoint sites configured to use non-English document library names? There's a line in the script to set the value for the language your tenant uses:

$SharedDocFolder = "/Shared%20Documents" # These values are to allow internationalization of the SPO document library URL. For French, this would be "/Documents%20partages"

Thanks for your fast response.
I've changed with the following line with no luck:
$SharedDocFolder = "/Documenti%20condivisi" # It's in italian
Below an example of the URL
https://tenant.sharepoint.com/sites/ClientVenueOperations/Documenti%20condivisi/Forms/AllItems.aspx?RootFolder=%2Fsites%2FClientVenueOperations%2FDocumenti%20condivisi%2FGeneral%2FTTTT&FolderCTID=0x01200022E44C59819C56418ADCEF3A32FD9D1C

What's in the $SPOData variable? The problem, is coming when the script attempts to parse it in this command:

$SPOUrl = $SPOData.WebUrl.SubString(0,$SpoData.weburl.IndexOf($SharedDocFolder))

Maybe the WebUrl part of $SPOData is not present... But I can't debug your tenant.... You need to do that,. You could just comment the command out of the script to see if that gets past the issue. AFAIK, all that this does is figure out the URL for the site and document library.

Hmmm... I tested to see if the code could parse the $SPOData,.WebURL property. It works.

$WebUrl = "https://tenant.sharepoint.com/sites/Test/Documenti%20condivisi"
$SharedDocFolder = "/Documenti%20condivisi"
$X = $WebUrl.SubString(0,$weburl.IndexOf($SharedDocFolder))
$X
https://tenant.sharepoint.com/sites/Test

Something odd going on...

BTW, it looks like this is an empty document library. Has anyone ever accessed it?

Hi, unfortunately the issue is related for each document library, I'm able to run script only if I put a comment in the script without any information about sharepoint

I added some code to the script that I think will help with local language values for SPO document libraries. You can download the updated script and try it out.

Hi @12Knocksinna now it works, thanks for your support.
Regatds,