PS > $file = Get-ChildItem C:\Documents\MyDocdocx PS > $fileGetType()FullName SystemIOFileInfo in VS .NET

Print QR Code ISO/IEC18004 in VS .NET PS > $file = Get-ChildItem C:\Documents\MyDocdocx PS > $fileGetType()FullName SystemIOFileInfo

PS > $file = Get-ChildItem C:\Documents\MyDocdocx PS > $fileGetType()FullName SystemIOFileInfo
Scanning QR Code JIS X 0510 In .NET
Using Barcode Control SDK for Visual Studio .NET Control to generate, create, read, scan barcode image in Visual Studio .NET applications.
Creating QR In .NET
Using Barcode encoder for .NET framework Control to generate, create QR Code ISO/IEC18004 image in VS .NET applications.
Now we can use the OpenRead method when adding a new file to a SharePoint library
Decoding QR-Code In .NET Framework
Using Barcode scanner for .NET framework Control to read, scan read, scan image in .NET applications.
Bar Code Encoder In .NET
Using Barcode printer for VS .NET Control to generate, create bar code image in .NET framework applications.
PS > $spFile = >> $spFileCollectionAdd("Shared Documents/MyDocdocx",$fileOpenRead(),$false)
Recognizing Bar Code In VS .NET
Using Barcode decoder for .NET framework Control to read, scan read, scan image in .NET framework applications.
Make Quick Response Code In Visual C#.NET
Using Barcode encoder for .NET framework Control to generate, create QR Code ISO/IEC18004 image in .NET applications.
In this example, we store the object returned by the Add method in a variable This allows us to add more information, such as metadata, to the file in SharePoint 2010 We add metadata using an object of the type MicrosoftSharePointSPListItem,
Painting QR In VS .NET
Using Barcode maker for ASP.NET Control to generate, create QR Code 2d barcode image in ASP.NET applications.
QR Code JIS X 0510 Generation In Visual Basic .NET
Using Barcode generator for Visual Studio .NET Control to generate, create Denso QR Bar Code image in .NET applications.
16:
Bar Code Generation In Visual Studio .NET
Using Barcode maker for .NET Control to generate, create bar code image in .NET framework applications.
Drawing USS Code 128 In .NET
Using Barcode generation for Visual Studio .NET Control to generate, create Code 128 Code Set B image in .NET applications.
Managing Documents in Document Libraries
Draw UPC Symbol In Visual Studio .NET
Using Barcode encoder for .NET Control to generate, create UPCA image in .NET applications.
International Standard Serial Number Generator In .NET
Using Barcode encoder for VS .NET Control to generate, create ISSN - 10 image in .NET applications.
which we retrieve using the Item property In the next example, we store the object in a variable and change the value of the list item s Modified field, and finally use the Update method to commit the changes to the content database
Encode Bar Code In .NET
Using Barcode printer for Reporting Service Control to generate, create bar code image in Reporting Service applications.
Painting Code 128B In None
Using Barcode printer for Online Control to generate, create Code 128 Code Set C image in Online applications.
PS > $spListItem = $spFileItem PS > $spListItem["Modified"] = (Get-Date 8/2/1987) PS > $spListItemUpdate()
Code-128 Creator In Objective-C
Using Barcode generation for iPad Control to generate, create Code 128 Code Set A image in iPad applications.
Barcode Recognizer In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
The Upload-SPFile function, shown next, wraps up the code described previously in a reusable function
Barcode Creation In None
Using Barcode encoder for Software Control to generate, create bar code image in Software applications.
Generating ECC200 In Objective-C
Using Barcode maker for iPad Control to generate, create DataMatrix image in iPad applications.
function Upload-SPFile([string]$url, [array]$files, [switch]$overwrite) { # Use the Get-SPList function to retrieve a list $spList = Get-SPList -url $url $spFolder = $SPListRootFolder $spFileCollection = $spFolderFiles # Loop through each file in the array foreach($file in $files) { $docURL = $spListRootFolderName + "/" + (Split-Path $file -Leaf) # Check if file already exists if(-not($overwrite) -and $spListParentWebGetFile($docURL)Exists) { Write-Host "File $file already exists" Continue } # Split-Path used to return the file name $spFileCollectionAdd( $docURL, $((Get-ChildItem $file)OpenRead()), $overwrite ) | Out-Null } }
EAN13 Printer In None
Using Barcode encoder for Microsoft Word Control to generate, create GS1 - 13 image in Word applications.
Making EAN13 In .NET Framework
Using Barcode maker for ASP.NET Control to generate, create EAN13 image in ASP.NET applications.
Run the Upload-SPFile function by typing the following:
PS > Upload-SPFile -url "http://nimaintranet/Shared Documents" ` >> -files C:\Myfile\MyDocdocx -overwrite
You can also use the Upload-SPFile function to add multiple files to a library in SharePoint In the next example, we use the Get-ChildItem cmdlet and retrieve all items in a specific directory with the docx or pptx file extension, and send those objects
PowerShell for Microsoft SharePoint 2010 Administrators
through a pipeline to the Select-Object cmdlet, retrieving the items full names with the ExpandProperty parameter
PS > Get-ChildItem C:\Documents\* -Include "*docx","*pptx" | >> Select-Object -ExpandProperty FullName C:\Documents\Annual Reportdocx C:\Documents\Content guidencepptx C:\Documents\Document Policydocx C:\Documents\Nima Design Principlespptx C:\Documents\Projectsxlsx
The output from this example could be stored in a variable and then used as input for the Upload-SPFile function, like this:
PS >> PS >> > $arrFiles = Get-ChildItem C:\Documents\* -Include "*docx","*pptx" | Select-Object -ExpandProperty FullName > Upload-SPFile -url "http://nimaintranet/Shared Documents" ` -files $arrFiles -overwrite
In this example, we add the overwrite switch parameter, which is used to overwrite existing files Note that if a file is checked out, the command will not work Later in this chapter, we will demonstrate how to handle checked-out documents using Windows PowerShell
Copying Documents Between Document Libraries
To copy files from one document library to another using Windows PowerShell, you can use the Add method supported by the MicrosoftSharePointSPFileCollection class, just as when uploading a file to a document library Let s start with retrieving the document libraries In this example, we use the Get-SPList function described in 14 to bind to the document libraries and store the destination file collection in a variable
PS > $sourceSPList = Get-SPList -url "http://nimaintranet/Shared Documents" PS > $destSPList = Get-SPList -url "http://nimaintranet/Site/Shared Documents" PS > $spFileCollection = $destSPListRootFolderFiles
Once we have retrieved the document libraries, we can loop through each file in the source document library and create it in the destination document library using a foreach loop
PS > foreach($item in $sourceSPListItems) {
In the foreach loop, we start by retrieving the current file using the GetFile method
>> $file = $sourceSPListParentWebGetFile($itemFile)
16:
Managing Documents in Document Libraries
Then we store the destination file s relative URL in a variable In the example, we replace the root folder name so that the destination file s URL corresponds with the destination document library
>> $targetDocUrl = $fileUrl -replace $sourceSPListRootFolderName, >> $destSPListRootFolderName
Files stored in a document library may be placed in folders and subfolders, so we need to take this into consideration A simple way of checking if a folder exists is by using the GetFolder method and checking the Exists property, as demonstrated here:
>> if(-not($destSPListParentWebGetFolder($fileParentFolderUrl)Exists)) {
If the folder doesn t exist, we iterate through each parent folder using a for loop In the next example, we split the folder s URL, loop through each segment, and create each folder in the destination document library
>> >> >> >> >> >> >> >> $folderURL = $fileUrlSplit("/") $addFolder = $folderURL[0] for($i=1;$i -lt ($folderURLCount -1);$i++) { $addFolder = $addFolder + "/" + $folderURL[$i] $destSPListParentWebFoldersAdd($addFolder) | Out-Null } # end for loop $addFolder = $null } # end if
Next, we check if the file already exists If it does, we continue with the next object in the pipeline
>> if(-not($overwrite) -and $destSPListParentWeb GetFile($targetDocUrl)Exists) { >> Write-Host "File $targetDocUrl already exists" >> Continue >> } # end if
Copyright © OnBarcode.com . All rights reserved.