fix: Correct temp library path construction and remove duplicate upload

This commit is contained in:
Bobby Abellana (aider) 2025-02-21 11:14:46 -08:00
parent 93ffe6a5a2
commit b725f52366

View File

@ -515,13 +515,25 @@ function Convert-Files {
# Upload the converted file to SharePoint
try {
# Verify file exists before trying to read it
if (-not (Test-Path $xlsxPath)) {
if (-not (Test-Path -LiteralPath $xlsxPath)) {
throw "Converted file not found at: $xlsxPath"
}
# Get the destination folder
$destinationFolder = $script:txtTempLib.Text
$uploadUri = "https://graph.microsoft.com/v1.0/drives/$($drive.Id)/root:/$($destinationFolder)/$($xlsxFileName):/content"
# Get the destination folder from the TempLibrary field
$tempLibrary = if ($script:txtTempLib.Text -eq "Shared Documents") {
"Documents"
} else {
$script:txtTempLib.Text
}
# Get the drive for the temp library
$tempDrive = $drives | Where-Object { $_.Name -eq $tempLibrary }
if (-not $tempDrive) {
throw "Temp library not found: $tempLibrary"
}
# Construct the upload URI for the temp library
$uploadUri = "https://graph.microsoft.com/v1.0/drives/$($tempDrive.Id)/root:/$($xlsxFileName):/content"
# Read the file content
$fileContent = [System.IO.File]::ReadAllBytes($xlsxPath)
@ -529,11 +541,11 @@ function Convert-Files {
# Upload the file
Invoke-MgGraphRequest -Uri $uploadUri -Method PUT -Body $fileContent -ContentType "application/octet-stream"
$script:txtStatus.Text += "Successfully uploaded to SharePoint: $destinationFolder/$xlsxFileName`n"
$script:txtStatus.Text += "Successfully uploaded to temp library: $tempLibrary/$xlsxFileName`n"
}
catch {
$script:txtStatus.Text += "Error uploading file: $($_.Exception.Message)`n"
if (-not (Test-Path $xlsxPath)) {
if (-not (Test-Path -LiteralPath $xlsxPath)) {
$script:txtStatus.Text += "File not found at: $xlsxPath`n"
}
continue # Move to the next file
@ -544,24 +556,6 @@ function Convert-Files {
continue # Move to the next file
}
# Upload the converted file to SharePoint
try {
# Get the destination folder
$destinationFolder = $script:txtTempLib.Text
$uploadUri = "https://graph.microsoft.com/v1.0/drives/$($drive.Id)/root:/$($destinationFolder)/$($xlsxFileName):/content"
# Read the file content
$fileContent = [System.IO.File]::ReadAllBytes($xlsxPath)
# Upload the file
Invoke-MgGraphRequest -Uri $uploadUri -Method PUT -Body $fileContent -ContentType "application/octet-stream"
$script:txtStatus.Text += "Successfully uploaded to SharePoint: $destinationFolder/$xlsxFileName`n"
}
catch {
$script:txtStatus.Text += "Error uploading file: $($_.Exception.Message)`n"
continue # Move to the next file
}
# Clean up temporary files
try {