.net barcode reader sdk Copying List Items in .NET

Create QR in .NET Copying List Items

Copying List Items
QR Code 2d Barcode Decoder In Visual Studio .NET
Using Barcode Control SDK for VS .NET Control to generate, create, read, scan barcode image in Visual Studio .NET applications.
Drawing QR-Code In .NET Framework
Using Barcode creator for Visual Studio .NET Control to generate, create QR Code 2d barcode image in .NET applications.
To copy items from one list in SharePoint 2010 to another list, you can use the AddItem method provided by the SPListItem class, just as when you create new list items The difference is that you read the field values from an existing list item and create a new list item in another list based on these values This requires that both lists contain the same fields The first step in copying list items from a list in SharePoint 2010 is retrieving the items from the source list You can do this by using the GetItems method provided by the SPList class In this example, we use the Announcements list
QR Code JIS X 0510 Decoder In Visual Studio .NET
Using Barcode reader for .NET Control to read, scan read, scan image in .NET framework applications.
Print Barcode In .NET
Using Barcode generator for .NET framework Control to generate, create barcode image in Visual Studio .NET applications.
PS > $sourceSPList = Get-SPList -url "http://nimaintranet/Lists/Announcements" PS > $sourceSPListItemCollection = $sourceSPListGetItems()
Bar Code Scanner In .NET Framework
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
Generating Quick Response Code In Visual C#.NET
Using Barcode generation for VS .NET Control to generate, create QR Code image in .NET framework applications.
Some fields in either list are marked as read-only, so we cannot copy the values of those fields We can handle this by looping through each field and checking if it is a read-only field In this example, we store the available fields in a variable so that we can use it when we loop through the list items
QR Code Maker In VS .NET
Using Barcode creator for ASP.NET Control to generate, create QR image in ASP.NET applications.
Printing QR In Visual Basic .NET
Using Barcode creator for .NET Control to generate, create Denso QR Bar Code image in VS .NET applications.
PS > $sourceSPFieldCollection = $sourceSPListFields
Encode Linear 1D Barcode In Visual Studio .NET
Using Barcode maker for .NET Control to generate, create Linear 1D Barcode image in VS .NET applications.
Bar Code Encoder In Visual Studio .NET
Using Barcode drawer for .NET Control to generate, create bar code image in Visual Studio .NET applications.
We also need to bind to the destination list In this example, we retrieve the Announcements list from a different site
Generate Bar Code In Visual Studio .NET
Using Barcode encoder for Visual Studio .NET Control to generate, create bar code image in VS .NET applications.
Leitcode Creation In .NET Framework
Using Barcode creation for .NET Control to generate, create Leitcode image in VS .NET applications.
PS > $destinationSPList = >> Get-SPList -url "http://nimaintranet/Site/Lists/Announcements"
EAN13 Maker In None
Using Barcode drawer for Software Control to generate, create EAN-13 image in Software applications.
Barcode Printer In None
Using Barcode drawer for Office Excel Control to generate, create bar code image in Excel applications.
Once we have retrieved the source list items and bound to the destination list, we can loop through each item and create it in the destination list First, we open a foreach loop
Generating 2D Barcode In Visual Basic .NET
Using Barcode drawer for .NET framework Control to generate, create 2D Barcode image in .NET applications.
Data Matrix 2d Barcode Generator In None
Using Barcode generator for Software Control to generate, create DataMatrix image in Software applications.
PS > foreach($spListItem in $sourceSPListItemCollection) {
Barcode Maker In None
Using Barcode generation for Font Control to generate, create barcode image in Font applications.
Decoding EAN / UCC - 13 In None
Using Barcode decoder for Software Control to read, scan read, scan image in Software applications.
PowerShell for Microsoft SharePoint 2010 Administrators
Barcode Creator In Java
Using Barcode creator for Android Control to generate, create barcode image in Android applications.
Reading UPC - 13 In Visual Basic .NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET applications.
In the foreach loop, we start by creating a new list item in the destination list
>> $newSPListItem = $destinationSPListAddItem()
Then we loop through each field stored in the spFieldCollection variable to exclude read-only fields and the Attachments field using an if statement Copying the attachments requires a different approach, so we will handle them later in the loop
>> foreach($spField in $sourceSPFieldCollection) { >> if($spFieldReadOnlyField -ne $True -and ` >> $spFieldInternalName -ne "Attachments") {
We then assign the values of every other field that is not read-only to the corresponding field of the new list item in the destination list We also close the if statement and the foreach loop
>> >> >> >> $newSPListItem[$($spFieldInternalName)] = $spListItem[$($spFieldInternalName)] }#end if }#end foreach
Next, we handle the attachments When adding attachments to a list item, we use the Add method provided by the SPAttachmentCollection class The Add method supports the leafName parameter, which accepts a string containing the name of the file to be attached, and the data parameter, which accepts a byte array containing the actual attachment First, we loop through the names of the list item s attachments
>> foreach($leafName in $spListItemAttachments) {
Next, we retrieve the actual attached file using the GetFile method provided by the SPWeb class The GetFile method accepts a URL as input We build the URL based on the UrlPrefix property of the SPAttachmentCollection object followed by the current attachment s name
>> $spFile = $sourceSPListParentWebGetFile( >> $($spListItemAttachmentsUrlPrefix + $leafName) >> )
Once we have the SPFile object stored in a variable, we can use the OpenBinary method to retrieve the corresponding byte array and add the attachment to the new list item
>> $newSPListItemAttachmentsAdd($leafName, $spFileOpenBinary()) >> } #end foreach
The last step is to commit the changes in the destination list using the Update method
>> $newSPListItemUpdate() >> #end foreach
15:
Managing SharePoint List Items
The function Copy-SPListItem, shown next, wraps up all the code used in this example
function Copy-SPListItem ([string]$source, [string]$destination) { # Get source list $sourceSPList = Get-SPList -url $source $sourceSPFieldCollection = $sourceSPListFields; $sourceSPListItemCollection = $sourceSPListGetItems(); # Get destination list $destinationSPList = Get-SPList -url $destination # Loop through each list Item and copy to destination list foreach($spListItem in $sourceSPListItemCollection) { # Create new Item $newSPListItem = $destinationSPListAddItem(); foreach($spField in $sourceSPFieldCollection) { # At first check fields that are not read only and attachments if ($spFieldReadOnlyField -ne $True -and ` $spFieldInternalName -ne "Attachments") { # Store value in new SPListItem object $newSPListItem[$($spFieldInternalName)] = $spListItem[$($spFieldInternalName)]; } } # Handle Attachments foreach($leafName in $spListItemAttachments) { $spFile = $sourceSPListParentWebGetFile( $($spListItemAttachmentsUrlPrefix + $leafName) ); $newSPListItemAttachmentsAdd($leafName, $spFileOpenBinary()); } # Update Item $newSPListItemUpdate(); } }
You can use the function by typing the following:
PS > Copy-SPListItem ` >> -source http://nimaintranet/Lists/Announcements ` >> -destination http://nimaintranet/Site/Lists/Announcements
Copyright © OnBarcode.com . All rights reserved.