Forum Discussion
Original Image Name Vs GUID
1. Methods to get the original file name
Query the file name through PowerShell
powershell
Connect-PnPOnline -Url “https://contoso.sharepoint.com/sites/site”
Get-PnPFile -Url “/sites/site/DocLib/2F3A4B50-1A2B-4C5D-6E7F-123456789ABC.jpg” |
Select-Object Name,@{N=“OriginalName”;E={$_.ListItemAllFields[“FileLeafRef”]}}
2. Via REST API
http
GET https://contoso.sharepoint.com/sites/site/_api/web/getfilebyserverrelativeurl('/sites/site/DocLib/2F3A4B50-1A2B-4C5D-6E7F- 123456789ABC.jpg')/listitemallfields?$select=FileLeafRef
Headers.
- Accept: “application/json;odata=verbose”
3. Keep the original naming solution
Rename the file before uploading
powershell
# Use PnP PowerShell to keep the original name
Add-PnPFile -Path “logo.jpg” -Folder “Shared Documents” -NewFileName “logo.jpg” -Values @{“Title”=“Company Logo”}
4. Disable automatic renaming (requires administrator privileges)
powershell
Set-PnPList -Identity “Documents” -EnableAssignUniquePermissions $false
5. Development Considerations
Front-end display processing
javascript
// Get the original name from the list item
const originalName = item.FileLeafRef;
Streaming Upload Optimization
csharp
// CSOM code example
FileStream fs = new FileStream(“photo.jpg”, FileMode.Open);
FileCreationInformation flci = new FileCreationInformation(); flci.
flci.Overwrite = true; flci.ContentStream = f
flci.Url = “photo.jpg”; // force the original name to stay