Answered by:
Import -SPWeb into different library same site

Question
-
I do an export spweb like
Export-SPWeb -Identity http://server/sites/mysite/ -IncludeVersions All -IncludeUserSecurity -path "D:\LibraryExport\live.cmp" -ItemUrl "Live"
Usually I do a "restore" via Import SPWeb like:
Import-SPWeb -Identity http://server/sites/mysite/test -IncludeUserSecurity -Force -path "D:\LibraryExport\live.cmp" - into a subsite called "test"
I wonder if there isn't a switch which allows me to import this export into a different library of the same site from where the export was taken without overwriteing the initial exported files. Something like:
Import-SPWeb -Identity http://server/sites/mysite/ -IncludeUserSecurity -Force -path "D:\LibraryExport\live.cmp" -ItemUrl "Archive" - which would mean it is re-imported into the already existing document library "Archive" of site "mysite". I know that -ItemURL does not work for import.
Thanks, Dieter
- Edited by Dieter Tontsch, mobileX Thursday, April 4, 2013 5:34 AM questoin wrong and spelling mistakes
Wednesday, April 3, 2013 8:16 AM
Answers
-
Actually Export/Import-SPWeb will allow you to do a single list or library as well (despite the name). The problem is that, using the out of the box versions of these cmdlets, you cannot import back to the same site. The reason for this is due to how the cmdlets effectively treat the unique object id for the list. It's possible to create a custom version of the cmdlets, which internally just uses the content deployment API (see my blog, http://blog.falchionconsulting.com, for an example of this where I created Export-SPWeb2 and Import-SPWeb2), and then set the appropriate property to tell SharePoint to use a different object ID which will then allow you to specify a different path where the list will be created. Ultimately though I think your best solution will be to simply save the list as a template.
Gary Lapointe, Blog: http://blog.falchionconsulting.com/, Twitter: http://twitter.com/glapointe Aptillon Inc.: http://www.aptillon.com
- Proposed as answer by Alex Brassington Sunday, April 7, 2013 10:12 AM
- Marked as answer by Kelly Chen 2012 Monday, April 8, 2013 2:21 AM
Friday, April 5, 2013 7:27 PM
All replies
-
If you wanted to import into a different site collection, you'd specify that via the -Identity switch on the Import-SPWeb cmdlet.
SharePoint - Nauplius Applications
Microsoft SharePoint Server MVP
MCITP: SharePoint Administrator 2010
-----------------------
This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.Wednesday, April 3, 2013 9:57 PM -
Hi, I know how to import into a different site collection. But I wanted to ask how can I import into the SAME SITE COLLECTION, even the same site, but a different LIBRARY only.
Sorry, I did a mistake in the initial question. I want to import into the same site collection but a different library. Like, if source is http://server/sites/mysite/mylibrary target shold be http://server/sites/mysite/mylibrary2.
Sorry and thanks, have also corrected the question above now.
Dieter
Thursday, April 4, 2013 5:32 AM -
The question doesn't really make sense in it's current format. Webs (or sites) don't exist in libraries, there is only one location in the object model where sites can exist, as such you're stuck with the option of either replacing the existing site in the site collection or creating a copy of it with a different URL.
I believe what you're actually asking is, 'how can I duplicate a library and include content' in which case you need something like this: http://office.microsoft.com/en-us/sharepoint-server-help/copy-or-move-a-library-by-using-a-library-template-HA101814157.aspx
Thursday, April 4, 2013 6:56 AM -
Hello, I try to explain once again.
I do an export of a library from http://server/sites/mysite/mylibrary where mylibrary is a library in site mysite containing a certain document (or more)
I know how I can import this library to a different site by using Import-SPWeb -Identity http://server/sites/mysite/test -IncludeUserSecurity -Force -path "D:\LibraryExport\live.cmp". This will automatically create a library with the same name of the one I have exported in the new site /test.
Now my question was if there is a posibility to re-import this export into the same site but without overwriteing the original library and creating a new one or importing to one which already exists filling it with the content of the export. So, in the end there should be two libraries in the same with the same content but different urls like:
http://server/sites/mysite/mylibrary - with the original content which was exported
http://server/sites/mysite/mylibrary2 - with the imported content.I can do http://server/sites/mysite2/mylibrary - but this is not what I want to achieve.
Regards,
Dieter
Thursday, April 4, 2013 7:12 AM -
Hello, I try to explain once again.
I do an export of a library from http://server/sites/mysite/mylibrary where mylibrary is a library in site mysite containing a certain document (or more)
I know how I can import this library to a different site by using Import-SPWeb -Identity http://server/sites/mysite/test -IncludeUserSecurity -Force -path "D:\LibraryExport\live.cmp". This will automatically create a library with the same name of the one I have exported in the new site /test.
Now my question was if there is a posibility to re-import this export into the same site but without overwriteing the original library and creating a new one or importing to one which already exists filling it with the content of the export. So, in the end there should be two libraries in the same with the same content but different urls like:
http://server/sites/mysite/mylibrary - with the original content which was exported
http://server/sites/mysite/mylibrary2 - with the imported content.I can do http://server/sites/mysite2/mylibrary - but this is not what I want to achieve.
Regards,
Dieter
When you use Export-SPWeb and Import-SPWeb you are exporting (and importing) the entire website (i.e. /mysite/), not just the library. If you just want to export and import the library then you need to get a reference to the library and use 'SaveAsTemplate'.
That will allow you to save an .stp file which can then be uploaded using either the GUI or
$site = get-spsite "http://myteam.lab/sites/team" $web = $site.OpenWeb() $spFolder = $web.getfolder("List Template Gallery") $spfilecollection = $spfolder.files $file = get-item c:\temp\MyTemplate.stp $spfilecollection.Add("_catalogs/lt/MyTemplate.stp", $file.OpenRead(), $true)
You can then create a list using the GUI or Powershell using that template.
Thursday, April 4, 2013 7:24 AM -
Actually Export/Import-SPWeb will allow you to do a single list or library as well (despite the name). The problem is that, using the out of the box versions of these cmdlets, you cannot import back to the same site. The reason for this is due to how the cmdlets effectively treat the unique object id for the list. It's possible to create a custom version of the cmdlets, which internally just uses the content deployment API (see my blog, http://blog.falchionconsulting.com, for an example of this where I created Export-SPWeb2 and Import-SPWeb2), and then set the appropriate property to tell SharePoint to use a different object ID which will then allow you to specify a different path where the list will be created. Ultimately though I think your best solution will be to simply save the list as a template.
Gary Lapointe, Blog: http://blog.falchionconsulting.com/, Twitter: http://twitter.com/glapointe Aptillon Inc.: http://www.aptillon.com
- Proposed as answer by Alex Brassington Sunday, April 7, 2013 10:12 AM
- Marked as answer by Kelly Chen 2012 Monday, April 8, 2013 2:21 AM
Friday, April 5, 2013 7:27 PM