SharePoint 2010 Exporting site fields to an XML file

2.8k views Asked by At

I have just started working with SharePoint 2010(you could say a bit of a late starter!) I have created a list via the GUI as i normally would with SharePoint 2007. I would then use Gary la pointe stsadm extentions to extract the fields XML and place them in to a feature within visual studio.

I was wondering can this still be done! I can't find the gl-Exportsitecolumns command in the 2010 stsadm commands!

Is there a powershell alternative?

Any help or guidance would be muchly appreciated.

Cheers Truez

2

There are 2 answers

0
jumbo On BEST ANSWER

I don't know about such alternative in powershell. BUT very easy solution can be this piece of code:

$w = Get-SPWeb http://localhost/subweb
$w.Fields | select SchemaXml # option 1: prints all xml to console
$w.Fields | select schemaxmlwithresourcetokens # option 2: the same, but with resource tokens
$w.Fields | %{ $_.schemaxml } | out-file c:\temp\fields.xml -encoding unicode #option 3: saves output to text file
0
Peter Mendez On

The alternative in powershell is found here: export-and-importcreate-site-content.html by Phil Childs

$sourceWeb = Get-SPWeb http://portal
$xmlFilePath = "C:\Install\Script-SiteContentTypes.xml"

#Create Export File
New-Item $xmlFilePath -type file -force

#Export Content Types to XML file
Add-Content $xmlFilePath "<?xml version=`"1.0`" encoding=`"utf-8`"?>"
Add-Content $xmlFilePath "`n<ContentTypes>"
$sourceWeb.ContentTypes | ForEach-Object {
    if ($_.Group -eq "Custom Content Types") {
        Add-Content $xmlFilePath $_.SchemaXml
    }
}
Add-Content $xmlFilePath "</ContentTypes>"

$sourceWeb.Dispose()