2

I have a project for a module, that deploys to a Sitecore site in IIS. So, my root project folder is C:\Dev\ContentExportTool\CET (where the .sln lives) and the site is at C:\inetpub\wwwroot\CET.dev.local.

I have an admin page that generates a package of my module with all of the necessary files and Sitecore items. However, the paths that it generates in the package are including the full file path from the project directory, which causes the files to be placed in the wrong place when the package is installed:

  1. In my project (in the CET folder) I have /sitecore/shell/example.aspx
  2. In my admin page, the code to add this file to the package is fileSource.Entries.Add(MainUtil.MapPath("C:\\Dev\\ContentExportTool\\CET\\sitecore\\shell\\example.aspx"));
  3. When I unzip the package file that's created, the files is at under /files/Dev/ContentExportTool/CET/sitecore/shell/example.aspx instead of /sitecore/shell/example.aspx
  4. When I install the package in Sitecore, that full folder structure is added to the website root instead of example.aspx getting added under /sitecore/shell

My package tool worked fine in an older solution where I included the module code in a Sitecore project where the codebase root was also the IIS website root (e.g. a basic solution where I only needed to run "Build" and not deploy files to another location); I expect this is because the site running the package code had the same root path as the files. But in trying to modernize with a new Sitecore 10 solution where the code is separate from the website, the paths are no longer generated correctly.

How do I change the destination path of the files in the package so that I get /files/sitecore/shell/example.aspx?

Here is the full code:

var packageProject = new PackageProject()
{
    Metadata =
        {
            PackageName = "Module",
            Author = "Me",
            Version = txtVersion.Value
        }
};

// files
var fileSource = new ExplicitFileSource();
fileSource.Name = "Files";
fileSource.Entries.Add(MainUtil.MapPath("C:\\Dev\\ContentExportTool\\CET\\sitecore\\shell\\example.aspx"));
packageProject.Sources.Add(fileSource);
packageProject.SaveProject = true;

var fileName = packageProject.Metadata.PackageName + ".zip";
var filePath = contentExportUtil.FullPackageProjectPath(fileName);

using (var writer = new PackageWriter(filePath))
{
    Sitecore.Context.SetActiveSite("shell");
    writer.Initialize(Installer.CreateInstallationContext());
    PackageGenerator.GeneratePackage(packageProject, writer);
    Sitecore.Context.SetActiveSite("website");

    Response.Clear();
    Response.Buffer = true;
    Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", fileName));
    Response.ContentType = "application/zip";

    byte[] data = new WebClient().DownloadData(filePath);
    Response.BinaryWrite(data);
    Response.Flush();
    Response.End();
}
1
  • What happens if you change to relati e path in code? I.e. fileSource.Entries.Add(MainUtil.MapPath("\\sitecore\\shell\\example.aspx")) assuming you run code in CET folder. Aug 12, 2023 at 20:56

1 Answer 1

0

Sitecore packages do not allow to specify different "source" and "destination" paths for files or items in the package. So if you want some files to be installed under the folder /sitecore/shell/, then you should package them from the website root rather than your project directory.

As a side note, if you try to package files using Sitecore Package Designer, it will not show any files or folders outside the website root because the application pool user may not even have permissions to read and write files that are not placed in the web root.

Package Designer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.