The process of building custom applications and tools that interact with Microsoft SharePoint, including SharePoint Online in Microsoft 365.
Please note that our forum is a public platform, and we will modify your question to hide your personal information in the description. Kindly ensure that you hide any personal or organizational information the next time you post an error or other details to protect personal data.
Hi @Sudheer
Good day, I hope you are doing well.
Looks like you are encountering an classic SharePoint / OneDrive filename restriction. SharePoint does not allow trailing spaces (or leading spaces) in file names. Even though the file was uploaded with an extra space at the end, the system treats a filename with a trailing space as different from the same name without the space. This is why you cannot easily replace or overwrite the file.
You could try to rename the existing file to remove the trailing space to troubleshoot it:
Go to the SharePoint document library in your browser.
Find the PDF file.
Click the ⋯ (ellipsis) next to the file > Rename.
Remove the extra space at the end of the filename (make sure it ends with .pdf with no space before it).
Click Save / Rename.
After renaming, try uploading your new version again, it should now overwrite properly.
If renaming does not work, you could try to upload your new PDF with a slightly different name (filename - updated.pdf).
Once uploaded, delete the old file that has the trailing space.
Then rename the new file to the correct name.
Additionally, you may try using a PowerShell cmdlet to resolve this issue by explicitly renaming the file to remove the trailing space. Run:
Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/SiteName -Interactive
Rename-PnPFile `
-ServerRelativeUrl "/sites/yoursite/Shared Documents/YourFileName .pdf" `
-TargetFileName "YourFileName.pdf" `
-Force
``
References:
Restrictions and limitations in OneDrive and SharePoint - Microsoft Support
powershell/documentation/Rename-PnPFile.md at dev · pnp/powershell · GitHub
I hope this helps.
Please understand that our initial reply may not always immediately resolve the issue. However, with your help and more detailed information, we can work together to find a solution.
Note: Please follow the steps in [our documentation] to enable e-mail notifications if you want to receive the related email notification for this thread.