Copy the xml file to sharepoint 2013 using powershell

Hi all,

I used below powershell script to copy the xml file to my sharepoint 2013 site in the docLibraryUrlName location.

             

$webUrl = "https://wwwsp2013.abcd.org/mncde"

$docLibraryName = "Documents"
$docLibraryUrlName = "SharePointlib"

$localFolderPath = "C:\Users\mmmvdes\Desktop\xmfolder"

#Open web and library

$web = Get-SPWeb $webUrl

$docLibrary = $web.Lists[$docLibraryName]

$files = ([System.IO.DirectoryInfo] (Get-Item $localFolderPath)).GetFiles()

ForEach($file in $files)
{

    #Open file
    $fileStream = ([System.IO.FileInfo] (Get-Item $file.FullName)).OpenRead()

    #Add file
    $folder =  $web.getfolder($docLibraryUrlName)

    write-host "Copying file " $file.Name " to " $folder.ServerRelativeUrl "..."
    $spFile = $folder.Files.Add($folder.Url + "/" + $file.Name, [System.IO.Stream]$fileStream, $true)
    write-host "Success"

    #Close file stream
    $fileStream.Close();
}

#Dispose web

$web.Dispose().

when run the script it is showing below error 

Copying file  VisualSPHelpItems.xml  to  /mncde/SharePointlib ...
Exception calling "Add" with "3" argument(s):
"<nativehr>0x80070003</nativehr><nativestack></nativestack>There is no file
with URL 'https://wwwsp2013.abcd.org/mncde/SharePointlib /abcde.xml' in this Web."
At line:8 char:5
+     $spFile = $folder.Files.Add($folder.Url + "/" + $file.Name,
[System.IO.Strea ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DirectoryNotFoundException.

Please help.How to resolve this.Thanks in advance.

Regards,

Praveen

May 19th, 2015 1:18am

Hi rajendra,

Thanks for u r reply.I need to copy the xml file in the below url location

https://wwwsp2013.abcd.org/mncde/_layouts/15/SharePointlib/manageitems.aspx.

Please help me where i need to change the script.Thanks in advance.

Regards,

Praveen

May 19th, 2015 2:32am

Hi

_layouts/15/SharePointlib/manageitems.aspx is In File System.

What is your document library url, and if there is folder in it ,share the url.

You can not upload the document using above script as it add in the sharepoint content db not on the file system

Free Windows Admin Tool Kit Click here and download it now
May 19th, 2015 2:52am

Hi rajendra,

Thanks for u reply.My requirement is i need to copy the xml file in the file system only(above mentioned url) means I activated one feature after activating iam going to that settings page in that page iam exporting this xml file.

I tried with below script also 

Import-SPWeb -Identity https://wwwsp2013.abcd.org/mncde -Path D:\xmllocation\abcde.xml -Force

it is throwing error like 

Import-SPWeb : Failed to read package file.
At line:1 char:1
+ Import-SPWeb -Identity https://wwwsp2013.abcd.org/mncde -Path
D:\xmllocation ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : InvalidData: (Microsoft.Share...CmdletImportWeb:
   SPCmdletImportWeb) [Import-SPWeb], SPException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletImportWe

How to achieve this please help.Thanks in advance.

Regards,

Praveen

May 19th, 2015 3:24am

Hi rajendra,

Can u please help me on this script i tried in different ways .Thanks in advance.

Regards,

Praveen

Free Windows Admin Tool Kit Click here and download it now
May 20th, 2015 8:28am

Hey Praveen

can u specify your exact requirement and want is your current system.


 "I activated one feature after activating iam going to that settings page in that page iam exporting this xml file."

exporting this xml file means do you want to export using button as you are on the page.

or you want to place the xml file  into your file system, after activating the feature.

May 20th, 2015 8:50am

Hi Rajendra,

Thanks for u r reply.I have sharepoint 2013 site in that site i activated visual sp help system feature.Then iam going to site settings page in that visual help settings  i am clicking on manage visual help items link in that link page in the ribbon iam clicking on import help items and select the xml file and click on import then the documents are added in this page.So the requirement is need to do this activity using powershell.Please help me on this.

Thanks in advance.

Regards,

Praveen

Free Windows Admin Tool Kit Click here and download it now
May 20th, 2015 9:13am

Hi rajendra,

Please help me on this requirement.

Regards,

Praveen

May 21st, 2015 12:50am

Hi

when you  import documents are added to document library or on the page.

Share your document library path before upload and after upload ,and let me know if the files are copied into the file system(14 folder)  or into the document library.

Free Windows Admin Tool Kit Click here and download it now
May 21st, 2015 1:48am

When i import the document sare added to the page only url is like

https://abcdes.org/abc/_layouts/15/xyz.sp/Manageitemss.aspx.And the xml configuration file i imported from the specifil location in the server.

May 21st, 2015 1:53am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics