-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImport-File.ps1
More file actions
71 lines (58 loc) · 2.96 KB
/
Import-File.ps1
File metadata and controls
71 lines (58 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<#
This Sample Code is provided for the purpose of illustration only and is not intended to be used in a production environment.
THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
We grant you a nonexclusive, royalty-free right to use and modify the sample code and to reproduce and distribute the object
code form of the Sample Code, provided that you agree:
(i) to not use our name, logo, or trademarks to market your software product in which the sample code is embedded;
(ii) to include a valid copyright notice on your software product in which the sample code is embedded; and
(iii) to indemnify, hold harmless, and defend us and our suppliers from and against any claims or lawsuits, including
attorneys' fees, that arise or result from the use or distribution of the sample code.
Please note: None of the conditions outlined in the disclaimer above will supercede the terms and conditions contained within
the Premier Customer Services Description.
#>
$Assem = (
“Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”
)
$Source = @”
using Microsoft.SharePoint;
using Microsoft.SharePoint.Deployment;
using System;
namespace StefanG.Tools
{
public class ImportDocument
{
private static string _destSiteUrl;
private static string _destLibrary;
public static void DoImport(string ExportLocation, string DestSiteUrl, string DestLibrary)
{
_destSiteUrl = DestSiteUrl;
_destLibrary = DestLibrary;
SPImportSettings importSettings = new SPImportSettings();
importSettings.SiteUrl = DestSiteUrl;
importSettings.FileLocation = ExportLocation;
importSettings.FileCompression = false;
importSettings.RetainObjectIdentity = false;
SPImport import = new SPImport(importSettings);
EventHandler<SPDeploymentEventArgs> startedEventHandler = new EventHandler<SPDeploymentEventArgs>(OnStarted);
import.Started += startedEventHandler;
import.Run();
}
static void OnStarted(object sender, SPDeploymentEventArgs args)
{
SPSite site = new SPSite(_destSiteUrl);
SPWeb web = site.OpenWeb();
SPList list = web.Lists[_destLibrary];
SPImportObjectCollection rootObjects = args.RootObjects;
foreach (SPImportObject io in rootObjects)
{
io.TargetParentUrl = list.RootFolder.ServerRelativeUrl;
}
web.Dispose();
site.Dispose();
}
}
}
“@
Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp
[StefanG.Tools.ImportDocument]::DoImport("c:\export", "http://jamondi-sp19:2000", "Dokumente2")