European Sharepoint 2013 Hosting Blog
Articles about European Sharepoint Hosting Service
Articles about European Sharepoint Hosting Service
Jan 14th
Jan 7th
In this blog, we are going to learn how to copy the attachments from a single list item to SharePoint library using PnP PowerShell. The following snippet helps, you to get the attachments from a list item and uploads to the shared Documents library in a current context site.
1 2 3 4 5 6 7 |
$cred = Get-Credential Connect-PnPOnline -Url https://ktskumartenant.sharepoint.com/sites/dev -Credential $cred $listitem = Get-PnPListItem -List Employee -Id 2 $attachments = ForEach-Object{Get-PnPProperty -ClientObject $listitem -Property "AttachmentFiles"} $attachments | ForEach-Object { Copy-PnPFile -SourceUrl $_.ServerRelativeUrl –TargetUrl “Shared Documents/$($_.FileName)” |
After running the powershell command, it asks us to confirm the sourceurl and target url. If the file already exists in the targeturl, we have to add -OverwriteIfAlreadyExists $true to avoid the file already exists error.
Below is the example copies the two attachments from the single list item to the folder within a SharePoint library.
Dec 23rd
1 |
For add="Add Navigation"(Function Name->addNavNode() )-> |
1 |
For retrieve="Show Navigations Names"(Function Name->checkNavNames())-> |
1 |
For remove="Remove Navigation"(FunctionName->removeNavNode())-> |
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
< script type = "text/javascript" language = "javascript" > var navNodes = [{ Name: "TeamSiteNavigation", url: "/sites/TeamSite", fromExternal: false }, { Name: "TopNavigation", url: "http://www.google.com", fromExternal: true }]; var oNavNodeColl = null; var nodeCreationInfo = null; function addNavNode() { var ctx = new SP.ClientContext.get_current(); if (ctx != undefined && ctx != null) { var oWeb = ctx.get_web(); this.oNavNodeColl = oWeb.get_navigation().get_topNavigationBar(); for (var i = 0; i < navNodes.length; i++) { var navObj = navNodes[i]; var nodeTitle = navObj.Name; var navNodeUrl = navObj.url; var navFromExternal = navObj.fromExternal; this.nodeCreationInfo = new SP.NavigationNodeCreationInformation(); nodeCreationInfo.set_title(nodeTitle); nodeCreationInfo.set_url(navNodeUrl); nodeCreationInfo.set_isExternal(navFromExternal); nodeCreationInfo.set_asLastNode(true); this.oNavNodeColl.add(nodeCreationInfo); } ctx.load(this.oNavNodeColl); ctx.executeQueryAsync(function() { alert("successfully added") }, function(sender, args) { alert('Request failed. ' + args.get_messege() + '\n' + args.get_stackTrace()); }); } } function checkNavNames() { var ctx = SP.ClientContext.get_current(); var oWeb = ctx.get_web(); var oNavNodeColl = oWeb.get_navigation(); var nodeColl = oNavNodeColl.get_topNavigationBar(); ctx.load(oNavNodeColl); ctx.load(nodeColl, 'Include(Title,Children.Include(Title,Children))'); ctx.executeQueryAsync(function() { var navNodeEnumerator = nodeColl.getEnumerator(); var nodeNames = ""; while (navNodeEnumerator.moveNext()) { var oNavNode = navNodeEnumerator.get_current(); nodeNames = nodeNames + '\n' + oNavNode.get_title(); } alert(nodeNames); }, function(sender, args) { alert('Request failed. ' + args.get_messege() + '\n' + args.get_stackTrace()); }); } function removeNavNode() { var navName = document.getElementById("Textbox").value; var ctx = SP.ClientContext.get_current(); var oWeb = ctx.get_web(); var oNavNodeColl = oWeb.get_navigation(); var nodeColl = oNavNodeColl.get_topNavigationBar(); ctx.load(oNavNodeColl); ctx.load(nodeColl, 'Include(Title,Children.Include(Title,Children))'); ctx.executeQueryAsync(function() { var navNodeEnumerator = nodeColl.getEnumerator(); var nodeNames = ""; while (navNodeEnumerator.moveNext()) { var oNavNode = navNodeEnumerator.get_current(); nodeNames = oNavNode.get_title(); if (nodeNames == navName) { oNavNode.deleteObject(); ctx.executeQueryAsync(function() { alert("successfully deleted"); }, function(sender, args) { alert('Request failed. ' + args.get_messege() + '\n' + args.get_stackTrace()); }); } } }, function(sender, args) { alert('Request failed. ' + args.get_messege() + '\n' + args.get_stackTrace()); }); } < /script> < input id = "addButton" type = "button" value = "Add Navigation" onclick = "addNavNode()" / >< br / >< div style = "marginTop:20px;" > & nbsp < /div>< input id = "checkButton" type = "button" value = "Show Navigations Names" onclick = "checkNavNames()" / >< br / >< div style = "marginTop:20px;" > & nbsp < /div>< label > Enter navigation name to delete < /label>< input id = "Textbox" type = "text" / >< input id = "removeButton" type = "button" value = "Remove Navigation" onclick = "removeNavNode()" > |
Dec 17th
Note
you will need “Site Collection Administrator” permission in the site collection to see “All Files” option.
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 |
#Set Parameters $<span class="attribute">SiteURL</span> = <span class="attribute-value">"Site URL"</span> $<span class="attribute">ListName</span> = <span class="attribute-value">"Library Internal Name"</span> $<span class="attribute">NewListURL</span> = <span class="attribute-value">"New Library Name"</span> #Connect to PNP Online Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) #this will change URL #Get the List $<span class="attribute">List</span>= <span class="attribute-value">Get</span>-PnPList -Identity $ListName -Includes RootFolder #sharepoint online powershell change list url $List.Rootfolder.MoveTo($NewListURL) Invoke-PnPQuery #this will change library title Set-PnPList -Identity $ListName -Title $NewListURL |
PowerShell to change List Name
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#Set Parameters $<span class="attribute">SiteURL</span> = <span class="attribute-value">"Site URL"</span> $<span class="attribute">ListName</span> = <span class="attribute-value">"Library Internal Name"</span> $<span class="attribute">NewListURL</span> = <span class="attribute-value">"New Library Name"</span> #Connect to PNP Online Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential) Set-PnPList -Identity $ListName -Title $NewListURL |
Dec 10th
1 |
Source,SourceDocLib,SourceSubFolder,TargetWeb,TargetDocLib,TargetSubFolder |
Dec 3rd
1 2 3 4 |
export interface ICopyPageProps { description: string; context: any; } |
1 2 3 4 5 6 7 |
const element: React.ReactElement<ICopyPageProps> = React.createElement( CopyPage, { description: this.properties.description, context: this.context } ); |
1 2 3 4 |
import { sp } from "@pnp/sp"; import "@pnp/sp/webs"; import { ClientsidePageFromFile, IClientsidePage, ClientsideWebpart } from "@pnp/sp/clientside-pages"; |
Step 4
1 |
var sourcePageURL = “https://****.sharepoint.com/sites/Test/SitePages/sourcepage.aspx”; |
Step 5
1 |
const pageTemplate = await ClientsidePageFromFile(sp.web.getFileByServerRelativePath(sourcePageURL)); |
Step 6
1 |
const newPage = await pageTemplate.copy(sp.web, “Page Name”, “Page Title”, false); |
Step 7
If true the page is published, if false the changes are persisted to SharePoint but not published [Default: true]
1 |
let WebpartPageWebpartInstance: string[] = this.getPageCustomWebPartsInstances(newPage); |