Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have implemented the code located at this link to export and import a list to a cmp file using powershell and the SPDeployment functions. While trying to better understand this code I came to the realization that I can use the same code (with a few adjustments) to export a single item by giving it the item unique ID, the type file (or list item), and the folder server relative url. My question is how would I modify the import-list to import this item in a specific folder/list. I read this article but it is in another language. I'm not sure how to convert it to powershell. I also, wasn't sure if the register-objectevent was the proper method but I also didn't want to do an "inline" function.

At first I thought I simply needed to give it a import object but there is no API to do so. I suspect I need to add this line:

Register-ObjectEvent -InputObject $import -EventName started `
-SourceIdentifier $import.started -Action { importStart   }

And the following function:

Function importStart([object]$sender, [object]$args)#[Microsoft.SharePoint.Deployment.SPDeploymentEventArgs]$args) 
{
   write-host "successfully entered started2"
   $web = #get list web somehow
   $list = #get list somehow

   $rootObjects = $args.RootObjects; 
   foreach ($io in $rootObjects) 
   { 
      if ($io.Type -eq [Microsoft.Sharepoint.Deployment.SPDeploymentObjectType]::File -or 
        $io.Type -eq [Microsoft.Sharepoint.Deployment.SPDeploymentObjectType]::ListItem)               
      {                                                             
         $io.TargetParentUrl = $list.RootFolder.ServerRelativeUrl;    
      }                                                             
      if ($io.Type -eq [Microsoft.Sharepoint.Deployment.SPDeploymentObjectType]::List)                   
      {                                                             
         $io.TargetParentUrl = $web.Url;                              
      }
   }
   $web.dispose();
}

But there are no event arguments passed to the -action command block or the function. Am I missing something here? Please help!

share|improve this question
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.