Exemple #1
0
        public void Initialize()
        {
            using (var ctx = TestCommon.CreateClientContext())
            {
                _site1Id = Guid.NewGuid().ToString();
                _site2Id = Guid.NewGuid().ToString();

                _site1RelativeUrl = $"/sites/PNPPS_Test_{_site1Id}";
                _site2RelativeUrl = $"/sites/PNPPS_Test_{_site2Id}";

                _site1Url = $"{TestCommon.GetTenantRootUrl(ctx)}{_site1RelativeUrl}";
                _site2Url = $"{TestCommon.GetTenantRootUrl(ctx)}{_site2RelativeUrl}";


                using (var site1Ctx = OfficeDevPnP.Core.Sites.SiteCollection.CreateAsync(ctx, new OfficeDevPnP.Core.Sites.CommunicationSiteCollectionCreationInformation()
                {
                    Url = _site1Url,
                    Lcid = 1033,
                    Title = "PnP PowerShell File Copy Test Site 1"
                }).GetAwaiter().GetResult())
                {
                    Folder folder = site1Ctx.Web.GetFolderByServerRelativeUrl(Site1RelativeFolderUrl);

                    FileCreationInformation fci = new FileCreationInformation
                    {
                        Content   = System.Text.Encoding.ASCII.GetBytes(TargetFileContents),
                        Url       = TargetFileName,
                        Overwrite = true
                    };
                    File fileToUpload = folder.Files.Add(fci);
                    site1Ctx.Load(fileToUpload);

                    fci.Url       = TargetFileNameWithAmpersand;
                    fci.Overwrite = true;
                    fileToUpload  = folder.Files.Add(fci);
                    site1Ctx.Load(fileToUpload);

                    fci.Url       = TargetFileNameWithHashtag;
                    fci.Overwrite = true;
                    fileToUpload  = folder.Files.Add(fci);
                    site1Ctx.Load(fileToUpload);

                    folder.EnsureFolder(TargetCopyFolderName);

                    // Prereq for CopyFile_EmptyFolderBetweenSiteCollections_Test
                    folder.EnsureFolder(EmptyFolderName);

                    // Prereq for CopyFile_FolderWithSkipSourceFolderNameBetweenSiteCollections_Test
                    var sourceFolder = folder.EnsureFolder(SourceFolderName);
                    fileToUpload = sourceFolder.Files.Add(fci);
                    site1Ctx.Load(fileToUpload);


                    // Prereq for CopyFile_FolderWithFoldersAndEmptyFolderBetweenSiteCollections_Test
                    var folderHirachyFolder0 = folder.EnsureFolder(SourceFolderWithFolders);
                    var folderHirachyFolder1 = folderHirachyFolder0.EnsureFolder(TargetCopyFolderName);

                    var folderHirachyFile0 = folderHirachyFolder0.Files.Add(fci);
                    var folderHirachyFile1 = folderHirachyFolder1.Files.Add(fci);
                    site1Ctx.Load(folderHirachyFile0);
                    site1Ctx.Load(folderHirachyFile1);

                    folderHirachyFolder1.EnsureFolder(EmptyFolderName);

                    site1Ctx.ExecuteQueryRetry();
                }
                OfficeDevPnP.Core.Sites.SiteCollection.CreateAsync(ctx, new OfficeDevPnP.Core.Sites.CommunicationSiteCollectionCreationInformation()
                {
                    Url   = _site2Url,
                    Lcid  = 1033,
                    Title = "PnP PowerShell File Copy Test Site 2"
                }).GetAwaiter().GetResult();
            }
        }