7

In my experience, the structure cannot be changed in SharePoint. However, I do need a modifiable construct of libraries and subsites for use in my company.

Moving documents is easy with a built-in function that I can access via a button, or via the Windows File Explorer. Unfortunately this is not possible with modern pages or page libraries.

My requirements are the following:

  • I want to move entire libraries within a site collection to other subsites.
  • I would also like to have the ability to move a single or multiple modern site pages to other site libraries at the same time.

Are there any hidden possibilities out of the box?

There are many third party migration tools out there, but they are all too expensive for me. (For example, ShareGate costs over 4000 dollars). Also, they can do a lot that I don't need.

Do you know of any ways I could implement my requirements?

0

After a few set of tests, I think I finally found out the problem.

I will document what I've found and in the end you'll find the actual solution.

There's always the chance that there are other variables in your scenario, but I hope this will help in some way.

**

The problem

Currently there is a sort of a built-in security mechanism in which certain files and file content are being blocked, to prevent harmful code execution.

File types such as .aspx are blocked by the api, meaning you cannot create your own or upload your own files, even copying from other sites won't work while this mechanism is enabled.

Some examples:

SharePoint Designer, renaming .txt to .aspx

enter image description here

File Explorer, renaming .txt to .aspx

enter image description here

The same will happen if we do any file creation, copying or moving through the api (401 unauthorized).

**

The solution

There are 2 settings that prevent script files and script content:

You'll need to disable at least DenyAddAndCustomizePages, which will automatically stop blocking your .aspx files.

I happen to have a gist here, even though it's a one liner to set it up:

https://gist.github.com/tiagoduarte/4e5e40bd19c29ed7d16e5412445f09e3

With the blocking problem out of the way, you can chose your flavor:

  • Use file explorer / manual reorganization
  • Code it in a method of choice

Here's a working example:

Console.WriteLine("Copying pages...");

ClientContext context = GetContext(webUrl);
Web web = context.Web;
List sourceList = web.Lists.GetByTitle("Site Pages");
ListItem sourceItem = sourceList.GetItemById(3);
context.Load(sourceItem);
context.Load(sourceItem.File);
context.Load(web.Webs);
context.ExecuteQuery();

Web subWeb = web.Webs[0];
List destList = subWeb.Lists.GetByTitle("Site Pages");
context.Load(destList);
context.Load(destList.RootFolder);
context.ExecuteQuery();

string newFileUrl = destList.RootFolder.ServerRelativeUrl + "/" + sourceItem.File.Name;

Console.WriteLine("Copying " + sourceItem.File.ServerRelativeUrl + " to " + newFileUrl);

FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, sourceItem.File.ServerRelativeUrl);
Microsoft.SharePoint.Client.File.SaveBinaryDirect(context, newFileUrl, fileInfo.Stream, true);
context.ExecuteQuery();

**

Sources

Types of files that cannot be added to a list or library

Access denied when uploading page to SitePages library in SharePoint Online

Enable-SPDesigner.ps1

SharePoint Online Management Shell

TL;DR

Disable DenyAddAndCustomizePages property of the SPOSite object

  • You wrote: "You must at least disable DenyAddAndCustomizePages". But isn't it enough just to do the setting in the Admin Center? But that applies globally to all pages? So I don't have to change the settings for each individual page and I don't have to deal with this management shell. – SharePointNewbie 6 hours ago
  • the setting that blocks you from creating/copying/moving .aspx files in Site Pages libraries is the DenyAddAndCustomizePages property. you must disable it. the script checkboxes are for allowing script web parts to pages, etc., which I wanted to reference as well but it won't help you. this setting will work for an entire site collection, so it is very quick and easy to perform and you only need to do it on site collections you'll work on, and you can put it back once you are done – Tiago Duarte 4 hours ago
  • I saw on your screenshot that you got an error message from SharePoint Designer. What exactly is the SharePoint Designer? Can I use it for my Office 365 SharePoint Online? I wanted to use the function "Open in Explorer" to move the files in the windows file explorer, but if there is a SharePoint Designer, I like to use it. – SharePointNewbie 3 hours ago
  • SharePoint Designer is an Office application that will allow you to connect to your sharepoint site and see all content, and make some changes. it's useful to have it alongside file explorer so you can check what either of them do and use the one that's better for you. I don't think you can use it to move stuff around though. you can grab it and use it for free here: microsoft.com/en-us/download/details.aspx?id=35491 – Tiago Duarte 3 hours ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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