fix: Correct temp library path construction and remove duplicate upload
This commit is contained in:
parent
93ffe6a5a2
commit
b725f52366
@ -515,13 +515,25 @@ function Convert-Files {
|
|||||||
# Upload the converted file to SharePoint
|
# Upload the converted file to SharePoint
|
||||||
try {
|
try {
|
||||||
# Verify file exists before trying to read it
|
# 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"
|
throw "Converted file not found at: $xlsxPath"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the destination folder
|
# Get the destination folder from the TempLibrary field
|
||||||
$destinationFolder = $script:txtTempLib.Text
|
$tempLibrary = if ($script:txtTempLib.Text -eq "Shared Documents") {
|
||||||
$uploadUri = "https://graph.microsoft.com/v1.0/drives/$($drive.Id)/root:/$($destinationFolder)/$($xlsxFileName):/content"
|
"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
|
# Read the file content
|
||||||
$fileContent = [System.IO.File]::ReadAllBytes($xlsxPath)
|
$fileContent = [System.IO.File]::ReadAllBytes($xlsxPath)
|
||||||
@ -529,11 +541,11 @@ function Convert-Files {
|
|||||||
# Upload the file
|
# Upload the file
|
||||||
Invoke-MgGraphRequest -Uri $uploadUri -Method PUT -Body $fileContent -ContentType "application/octet-stream"
|
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 {
|
catch {
|
||||||
$script:txtStatus.Text += "Error uploading file: $($_.Exception.Message)`n"
|
$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"
|
$script:txtStatus.Text += "File not found at: $xlsxPath`n"
|
||||||
}
|
}
|
||||||
continue # Move to the next file
|
continue # Move to the next file
|
||||||
@ -544,24 +556,6 @@ function Convert-Files {
|
|||||||
continue # Move to the next file
|
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
|
# Clean up temporary files
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user