Subscribe in a reader

Add to Technorati Favorites Import Publishing Page Content from XML

Import Publishing Page Content from XML

by JamieMcAllister 10/22/2008 11:53:00 AM
 

It seems like a good move to compliment the recent Content Export article with one about importing XML content into your MOSS Publishing Site (which might be a variation). The good news is that this process is fairly straightforward. (If you’ve output sufficient identifiers when you exported your content that is!)

 

Below is some sample export XML;

 <pages>

- <web guid="4a167efa-837b-40d6-a39b-f17b70f6ce61">

- <page url="https://mydomain.com/FR/Pages/GlossaryofTerms.aspx" guid="0e699d23-248f-416f-84e6-42820c8d4024">

- <fields> 

<field guid="fb564e0f-0b70-4ab9-b863-0177e6ddd247" fieldname="Title">Glossary of Terms</field>  

</fields> 

</page> 

</web> 

</pages> 

We have a collection of Webs, those webs contain pages, and those pages contain fields. Each level of that hierarchy web->Page->Field has its appropriate Guid so we can find it again easily. The url attribute of page is for our human readership, as is the fieldname attribute for field. (btw “Glossary of Terms” is just the basic content for this particular field).

 

So, we are going to iterate through the XML, obtaining references to web, page, and field instances as appropriate before pushing page content into them. Here we go;

 

Get our Site Collection

using (SPSite site = new SPSite(SPContext.Current.Site.Url))

 

Get the web guid from the XML and use that to get our publishing web;

string webGuid = webNode.Attributes[xmlGuid].Value; 

PublishingWeb pw = PublishingWeb.GetPublishingWeb(site.OpenWeb(new Guid(webGuid)));

 

Now we have our publishing web we get the Publishing Pages very easily;

PublishingPageCollection ppCol = pw.GetPublishingPages();

 

We know from the XML that the publishing pages we’re interested in reside in that web so we get the appropriate identifiers, and access them;

 string pageGuid = pageNode.Attributes[xmlGuid].Value; 

PublishingPage pp = ppCol[new Guid(pageGuid)];

 

Depending on your setup, you may also need to do a checkout at this point as we will be modifying the page;

 

pp.CheckOut();

  

Finally, set the content, and update the page, and the job is done;

 string fieldGuid = fieldNode.Attributes[xmlGuid].Value;

string fieldContent = SPHttpUtility.HtmlDecode(fieldNode.InnerText); //Set the content

pp.ListItem[new Guid(fieldGuid)] = fieldContent; 

pp.Update();//Update after completing all field changes, not after each one 

You might need a pp.Checkin() at this stage, but that depends on your setup.

 

Iterate through the XML in that way, and the import is done! This code avoids the iteration of the export code, but is more processor intensive because we are changing items rather than just reading them.

 

So, you now have a simple solution to start translating your variations content.

 

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

.NET | CMS | Sharepoint | Translatable Columns | Variations | WCM

Related posts

Comments

1/5/2009 9:39:11 AM

Busby SEO Test

Thank you for the code. I really appreciate your work

Busby SEO Test us

1/13/2009 7:10:51 AM

busby seo test

thanks for the code

busby seo test us

Powered by BlogEngine.NET 1.3.0.0
Theme by Mads Kristensen

About the author

Jamie McAllister Jamie McAllister
Manchester (UK) Based Consultant for Northridge Solutions Ltd.


Jamie McAllister Linked In
        
        
        
        

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Sign in

Disclaimer: The software and source code on this website is provided "AS IS"
with no warranties of any kind. The entire risk arising out of the use or
performance of the software and source code is with you.