1

I am aware of how to create a page in Sharepoint declaratively, via markup, like so:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="Pages" Url="Pages" Path="PageLayouts">
    <File Url="Connection Test.aspx" Type="GhostableInLibrary" Path="PageLayout.aspx">
      <AllUsersWebPart WebPartOrder="1" WebPartZoneID="RightColumn" ID="Provider">...</AllUsersWebPart>
      <AllUsersWebPart WebPartOrder="2" WebPartZoneID="Body" ID="Consumer">...</AllUsersWebPart>
      <Property Name="Title" Value="Connection Test" />
      <Property Name="ContentType" Value="Page" />
    </File>
  </Module>
</Elements>

But I'm interested in the reverse process -- how can I obtain this code for a page that already exists in my 'Pages' library? I tried downloading a copy of the page, and also opening it in Sharepoint Designer, but all I see is the ASPX code of the page. I'm interested in the XML markup code that generated that page. Is there a way?

UPDATE: Clarifying the question a little more:

  1. I first create a simple web-part page from the Sharepoint UI, via Site Actions > More Options > Web Part Page. I then give it a name (say TestPage.aspx), and select the Document Library (say Pages) to save the page in.
  2. Next, I add web parts to the page.
  3. Also, I establish web part connections, if any.
  4. And then, hit Stop Editing to save the page.

So now the page TestPage.aspx is available in Pages library. To view the code behind the page, I click on the page, and choose Download a copy (or alternatively, right-click the page, and choose Edit in Microsoft Sharepoint Designer), but all I see here is the ASPX code that doesn't include any XML markup like the one above.

If it's possible to write XML to create a page (like the example above), I'm guessing there's a way I can look at how the XML for the web parts and web part connections are coded by Sharepoint when a page is created manually. How do I get this XML?

1

You can save your site as a template:

When you save your site as a template, you create a Web Solution Package, or WSP. A WSP is a CAB file that uses the solution manifest. The solution that you create is stored in the solutions gallery for the SharePoint site collection. Once you save the template, a solution file (.wsp) is created and stored in the solutions gallery where you can download or activate the solution.

What gets saved in a template?

When you save a SharePoint site as a template, you're saving the overall framework of the site — its lists and libraries, views and forms, and workflows. In addition to these components, you can include the contents of the site in the template; for example, the documents stored in the document libraries. This could be useful to provide sample content for users to get started with. Consider that this could also increase the size of your template beyond the default 50-MB site template limit.

Most of the objects in a site are included and supported by the template. However, there are several objects and features that are not supported.

Supported Lists, libraries, external lists, data source connections, list views and data views, custom forms, workflows, content types, custom actions, navigation, site pages, master pages, modules, and web templates.

Unsupported Customized permissions, running workflow instances, list item version history, workflow tasks associated with running workflows, people or group field values, taxonomy field values, publishing pages and publishing sites, My Sites, and stapled features.

Tip:
If, under Site Actions, you don't see the option to 'Save site as a Template', then as a workaround, you may access the save site as template through http://sitename/_layouts/savetmpl.aspx directly.

  • How exactly does that address the question? Where is there any mention of XML in your pasted answer? – teylyn Jan 8 '14 at 7:39
  • 1
    I you export youre site you will get the xml code of the existing pages. I thought that was wat he wanted. If not then the question is not clear for me. Instead of downvoting a comment could be enough – Remko Jan 8 '14 at 8:18
  • You may want to consider that this is not implied in your answer. If XML markup becomes visible with your suggested method, it still is not immediately obvious. Why not add a few words to point to the exact location or method to see the XML? THAT would be helpul. Not everyone knows what you know. That's why people come here and ask questions. – teylyn Jan 8 '14 at 8:20
  • 1
    I think pointing to a direction is helpfull. Steps can be found in the link I provided. I think its not use full to recreate MSDN on this site. But that is a discussion we should not have as a comment. – Remko Jan 8 '14 at 8:44
  • This worked, and nearly a year later, I had to do it again and this answer helped. Again! – SNag Mar 31 '15 at 16:02
1

According to my understanding, you are referring to page layouts from which all pages in page library are created from. Page layouts are stored in the Master Page Gallery and you could easily update their XML markup using SharePoint designer or Visual Studio. See post for further information

  • Thanks for the answer, but sorry; this is not what I'm after. I've updated the question for better clarity -- I'm essentially looking to save a manually created page so I may deploy it on other site collections, without having to create the same page on each of those site collections over and over again. – SNag Jan 8 '14 at 13:12
0

The Module is just a provisioning mechanism - it really has no context in the scenario you presented. It says, "Take this file which lives in the location specified by the Path attribute, and provision it to SharePoint at the url specified by the Url attribute."

You can generate some Module code by saving a site as a template as indicated by Remko, then creating a Visual Studio project of type "Import Solution Package" using the wsp as input when prompted in the wizard. This is very useful if what you're trying to do is reverse-engineer a site to figure out how to provision certain elements (like pages).

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.