
function ExportListData($siteUrl, $webRelativeUrl, $listName, $exportListPath) {
    Write-Host "$listName ..."   
	
	if($webRelativeUrl.StartsWith("/")){ 
		$webUrl = $siteUrl + $webRelativeUrl
		$listUrl = $webRelativeUrl+"/Lists/"+$listName
	}
	else {
		$webUrl = $siteUrl+"/" + $webRelativeUrl 
		$listUrl = "/"+$webRelativeUrl+"/Lists/"+$listName
	}	
	
	if ($listUrl.StartsWith("//")){
		$listUrl = $listUrl.Replace("//", "/")
	}
	
    Export-SPWeb -Identity $webUrl -Path $exportListPath -ItemUrl $listUrl -NoFileCompression -IncludeVersions All -IncludeUserSecurity -ErrorAction Stop		
}


function ExportLibraryData($siteUrl, $webRelativeUrl, $listName, $exportListPath) {
    Write-Host "$listName ..."   
	
	if($webRelativeUrl.StartsWith("/")){ 
		$webUrl = $siteUrl + $webRelativeUrl
		$listUrl = $webRelativeUrl+"/"+$listName
	}
	else {
		$webUrl = $siteUrl+"/" + $webRelativeUrl 
		$listUrl = "/"+$webRelativeUrl+"/"+$listName
	}		

	if ($listUrl.StartsWith("//")){
		$listUrl = $listUrl.Replace("//", "/")
	}
	
    Export-SPWeb -Identity $webUrl -Path $exportListPath -ItemUrl $listUrl -NoFileCompression -IncludeVersions All -IncludeUserSecurity -ErrorAction Stop		
}


function ExportListDataAndDeleteDatFiles($siteUrl, $webRelativeUrl, $listName, $exportListPath) {
    Write-Host "$listName ..."   
	
	if($webRelativeUrl.StartsWith("/")){ 
		$webUrl = $siteUrl + $webRelativeUrl
		$listUrl = $webRelativeUrl+"/Lists/"+$listName
	}
	else {
		$webUrl = $siteUrl+"/" + $webRelativeUrl 
		$listUrl = "/"+$webRelativeUrl+"/Lists/"+$listName
	}
	
	
 
    Export-SPWeb -Identity $webUrl -Path $exportListPath -ItemUrl $listUrl -NoFileCompression -IncludeVersions All -IncludeUserSecurity -ErrorAction Stop
	
	$datFileMaks = $exportListPath+"\*.dat"
	Remove-Item $datFileMaks
}

function CleanUpManifest($exportListPath){ 
 
 	$xmlFile = $exportListPath+'\Manifest.xml'
	Write-Host $xmlFile
	[xml]$xml = gc $xmlFile	
	
	$ns = @{
         e = 'urn:deployment-manifest-schema'
       }

	$xml | Select-Xml '//e:SPObjects/e:SPObject[@ObjectType="SPFile"]' -Namespace $ns | 
	Foreach { 
		$_.Node.ParentNode.RemoveChild($_.Node)
	}
	
	$xml | Select-Xml '//e:SPObjects/e:SPObject[@ObjectType="SPList"]' -Namespace $ns | 
	Foreach { 
		$_.Node.ParentNode.RemoveChild($_.Node)
	}
	
	$xml.Save($xmlFile)
}

function ImportListData($webUrl, $listPath)
{
	Import-SPWeb -Identity $webUrl -Path $listPath -NoFileCompression -IncludeUserSecurity 
}

function ImportListDataWithNotification($webUrl, $dataPath)
{
	Write-Host ("Importing list data form '{0}' ..." -f $dataPath)
	ImportListData $webUrl $dataPath
}