We have a problem where the Download script used as a right-click menu option is throwing an error.
Looking into the script, the problem appears to be how the value [Sitecore.Configuration.Settings]::DataFolder
It's coming back with a relative path that seems to be used inconsistently by the saving and the downloading respectively.
If I hard-code this value to be absolute, the functionality works as expected.
In my sitecore config file I have the following, which I assume is what's being read here:
<sitecore database="SqlServer" xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sc.variable name="dataFolder" value="/App_Data" />
I could patch this value to be the absolute path, but I'm not quite sure if there would be other implications for this.
Although it's not a big deal for me to maintain my own version of the Powershell script, I want to check if this is actually something I should address in my config file - or even whether this is a weakness in the Powershell script itself.
Has anyone come across this before - and if so, how did you address it?
Have edited to include the actual script that performs the zip/download:
function ZipItems( $zipArchive, $sourcedir )
{
Set-Location $sourcedir
[System.Reflection.Assembly]::Load("WindowsBase,Version=3.0.0.0, `
Culture=neutral, PublicKeyToken=31bf3856ad364e35") | Out-Null
$ZipPackage=[System.IO.Packaging.ZipPackage]::Open($zipArchive, `
[System.IO.FileMode]::OpenOrCreate, [System.IO.FileAccess]::ReadWrite)
$items = @(Get-Item $sourceDir) + (Get-ChildItem -recurse $sourceDir)
[byte[]]$buff = new-object byte[] 40960
$i = 0;
ForEach ($item In $items) {
$i++
if([Sitecore.Resources.Media.MediaManager]::HasMediaContent($item)){
$mediaItem = New-Object "Sitecore.Data.Items.MediaItem" $item;
$mediaStream = $mediaItem.GetMediaStream();
$fileName = Resolve-Path -Path $item.ProviderPath -Relative
$fileName = "$fileName.$($item.Extension)".Replace("\","/").Replace("./","/");
"Added: $fileName"
Write-Progress -Activity "Zipping Files " -CurrentOperation "Adding $fileName" -Status "$i out of $($items.Length)" -PercentComplete ($i *100 / $items.Length)
$partUri = New-Object System.Uri($fileName, [System.UriKind]::Relative)
$partUri = [System.IO.Packaging.PackUriHelper]::CreatePartUri($partUri);
$part=$ZipPackage.CreatePart($partUri, "application/zip", [System.IO.Packaging.CompressionOption]::Maximum)
$stream=$part.GetStream();
do {
$count = $mediaStream.Read($buff, 0, $buff.Length)
$stream.Write($buff, 0, $count)
} while ($count -gt 0)
$stream.Close()
$mediaStream.Close()
}
}
$ZipPackage.Close()
}
$location = get-location
$time = Get-Date -format "yyyy-MM-d_hhmmss"
$zipName = Split-Path -leaf $location | % { $_ -replace " ", ""}
$dataFolder = [Sitecore.Configuration.Settings]::DataFolder
$zipPath = "$dataFolder\$zipName-$time.zip"
ZipItems $zipPath $location
Download-File -FullName $zipPath | Out-Null
Remove-Item $zipPath
Close-Window