File Upload with HashTable and Multie Value Columns

Was trying to upload some documents the other day using an XML file with the metadata.  I needed to split a bunch of data out and submit it to SharePoint as a list column with Multiple Values.  This, and lookup columns, you really have to understand how the data is sored in SQL first before trying to just do thls.  What I did was:
 
  • Upload a couple of items through the UI and set the values.
  • Open up SQL and run a query to find the detail:

select nvarchar10,nvarchar11,ntext2,* from alluserdata WHERE tp_LeafName = ‘Test File.txt’ order by tp_version desc

  • The columns you want to see with the values you can fine in the SPList.SchemaXml…file the Field element with the field it stores the data in
  • From here, I realized the multiple value fields are completely surrounded and split with ;#.  For example, if you have values A,B, then it would be ;#A;#B;#.

That is all, upload these files with the SPFolder.Files.Add() method and create yourself a HashTable with the metadata and you are off and running…of course this is real easy through PowerShell:

$site = new-object microsoft.sharepoint.spsite(http://server)

$web = $site.rootweb

#$list = $web.Lists["ListName"]

#$list.Schema.Xml

$folder = $web.getfolder("/ListName")

 

$x=@{}

#Plain Text Field

$x.add("Plain","Blah blah")

#Field with Choice and Checkboxes…

$x.add("MultiValue",";#A;#B;#")

$bytes=[byte[]]get-content export.csv -encoding byte

$file = $folder.files.add("Test File.txt",$bytes,$x,$true)

Advertisements