Click here to Skip to main content
13,344,508 members (49,783 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 11 Jul 2014

Read .xml Files and Add them into SharePoint 2010 through PowerShell

, 11 Jul 2014
Rate this:
Please Sign up or sign in to vote.
How to read XML files and add them into SharePoint 2010 through Powershell


Today, I’ll be showing you a PowerShell script which picks up the data from XML files and puts it into SharePoint list.

This is an important PowerShell which you will see as it will be used to migrate .NET applications to SharePoint. Most of the .NET applications use XML files to store data. So here in this PowerShell, I will be looping all the XML files of a complete application and put them into SharePoint.

Seems easy, right? But was tough for me.

So the title of this article will be:

Read .xml Files and add them into SharePoint 2010 through PowerShell

Open SharePoint 2010 Management Shell by going to Start >> All Programs >>SharePoint >>Microsoft SharePoint 2010 Products >> SharePoint 2010 Management Shell (Run as Administrator).

Run the following script.

------------------Save the below in a Notepad , save it as .ps1 file and run it------------

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null 
[System.Xml.XmlDocument] $XmlDoc = new-object System.Xml.XmlDocument

Get-ChildItem "Put the path of all xml files here" *.xml -recurse | 
% { 
    $XmlDoc = [xml](Get-Content $_.fullname)

    $path =  $XmlDoc.ExportedContentItem.path
    $name =  $
    $GUID =  $XmlDoc.ExportedContentItem.ID

    $out = $path + "/" + $name + "`t" + $GUID
Write-Host -ForegroundColor Green $_.fullname " is  reading to the list item"     

$url = "Put the site Url u want to add into"
$listTitle = "List name" 
$web = Get-SPWeb $url
$list = $web.Lists.TryGetList($listTitle)
if ( $list -ne $null)
#get data from the xml tags and read them by assigning them
                                         $EmpIdadding = $XmlDoc.GetElementsByTagName("ID")
			$Nameadding = $XmlDoc.GetElementsByTagName("Name")
Foreach ($empid in $EmpIdadding){
 # Get InnerXML value of ID  node and assign it to string
Foreach ($name in $Nameadding){
 # Get InnerXML value of name node and assign it to string

#Assign the string values to the list item
            $item  =$list.AddItem();
                                           $item["name"] = $strname
			$item["empid"] = $strempid
	Write-Host -ForegroundColor Green $_.fullname " is added successfully to the list item"  	  
$Web.AllowUnsafeUpdates = $false

That's it, looks simple, but eases us developers of a lot of burden. Enjoy! Cheers!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Argentina Argentina
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Lydia Gabriella16-Jul-14 11:43
memberLydia Gabriella16-Jul-14 11:43 
GeneralRe: My vote of 5 Pin
memberMANPREET SINGH8-Aug-14 7:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 11 Jul 2014
Article Copyright 2014 by MANPREET SINGH
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid