'How to create webpart page with specific layout template?

This is similar question asked as below, just want to have wider audience to answer.

https://docs.microsoft.com/en-us/answers/questions/722821/how-to-create-webpart-page-which-specific-layout-t.html

I have a requirement where I need to take backup of webpart page and restore it later if page got deleted. I am able to take the backup of webpart page and webparts of it using LimitedWebPartManager.

While restoring, when I create webpart page using below code, it have layout template similar to FullPage but its zone name is main, only single zone.

Code:

var pageTitle = "newPage0101.aspx";
var file = targetList.RootFolder.Files.AddTemplateFile(targetList.RootFolder.ServerRelativeUrl + "/" + pageTitle, TemplateFileType.StandardPage);
clientcontext.Load(file);
clientcontext.ExecuteQuery();

However backed up page have "Header, Footer, 2 Columns, 4 Rows", and would like to create webpart page with same layout template, so could anyone please help here?

Available templates:

  1. Header, Footer, 3 Columns
  2. Full Page, Vertical
  3. Header, Left Column, Body
  4. Header, Right Column, Body
  5. Header, Footer, 2 Columns, 4 Rows
  6. Header, Footer, 4 Columns, Top Row
  7. Left Column, Header, Footer, Top Row, 3 Columns
  8. Right Column, Header, Footer, Top Row, 3 Columns


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source