0

I need a way (using code) to upload files to a SharePoint 2013 Document Library without having to go through the file drag and drop feature and I am limited to using VB script right now.

After doing some research I found code that uploads files to SharePoint along with the metadata values however I am having an issue updating a other metadata such as a choice column in SharePoint 2013 using SOAP calls through Vb script. here is the code

    Const strLocalFile = "C:\temp\myLocalFile.pdf"
    Const spBASE_URL = "https://thesharepointdomian/sites/yoursite/"
    Const spDOC_LIB = "Your SP Doc Library Name"
    Const spFILE_NAME = "NewFile.pdf"
    Const spCONTENT_TYPE = "0x000000000000000000000000000000000000000"

    Set ObjectStream = CreateObject("ADODB.Stream")
    Set ObjectDOM = CreateObject("Microsoft.XMLDOM")
    Set ObjectElement = ObjectDOM.createElement("TMP")
    Set ObjectHTTP = CreateObject("Microsoft.XMLHTTP")

    ObjectStream.Open
    ObjectStream.Type = 1 
    ObjectStream.LoadFromFile (strLocalFile)
    BinaryFile = ObjectStream.Read()
    ObjectStream.Close

    ObjectElement.DataType = "bin.base64" 
    ObjectElement.nodeTypedValue = BinaryFile
    EncodedFile = ObjectElement.Text


    strURLService = spBASE_URL + "_vti_bin/copy.asmx"
    strSOAPAction = "http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems"
    strSOAPCommand = "<?xml version='1.0' encoding='utf-8'?>"+_
    "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
    xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"+_
    "<soap:Body>"+_
    "<CopyIntoItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>"+_
    "<SourceUrl>" + strLocalFile + "</SourceUrl>"+_
    "<DestinationUrls>"+_
    "<string>" + spBASE_URL + spDOC_LIB + "/" + spFILE_NAME + "</string>"+_
    "</DestinationUrls>"+_
    "<Fields>"+_
    "<FieldInformation Type='Text' InternalName='Title' DisplayName='Title' Value='Hello' />"+_
    "<FieldInformation Type='Choice' InternalName='MyChoices' DisplayName='MyChoices' Value='AAA' />"+_
    "</Fields>"+_
    "<Stream>" + EncodedFile + "</Stream>"+_
    "</CopyIntoItems>"+_
    "</soap:Body>"+_
    "</soap:Envelope>"

    ObjectHTTP.Open "Get", strURLService, False
    ObjectHTTP.SetRequestHeader "Content-Type", "text/xml; charset=utf-8"
    ObjectHTTP.SetRequestHeader "SOAPAction", strSOAPAction
    ObjectHTTP.Send strSOAPCommand

    MsgBox (ObjectHTTP.responseText)

The code works in uploading the file and changing the "title" but I am having issues with the other metadata types specifically choice columns. I am new to web service calls in general and having an issue on the syntax for changing other column metadata. Can someone give me some guidance on this ?

Lets say I have a choice column named "MyChoices" set for multiple values. which has these options 'AAA", "BBB", "CCC", "DDD". How do I change the metadata information to read lets say "AAA" and "DDD". Also would help if anyone knows how to change other types like number columns and date columns.

Thanks in advance

1
  • In Order to get the correct XML Structure Use SharePoint Manager 2013 to get the correct Field XML. To set multiple values of Choices set it to ;<FieldInformation Type='Choice' InternalName='MyChoices' DisplayName='MyChoices' Value=';#AAA;#DDD;' /> . Also check the link for other column types msdn.microsoft.com/en-us/library/office/ms196289.aspx Commented Nov 19, 2016 at 1:14

1 Answer 1

0

Suppose you have below choice field value set in column

Canada

Germany

Great Britain

Ireland

United States

You need to use below format to update

   <FieldInformation Type='Choice' InternalName='Country' DisplayName='Country' Value=';#Germany;#United States;' />

Important point to note here is the order of values you pass in "Value" node. it has to be precise in order which it is kept in column settings, else it will not update values. So in above example if you pass below XML, though it will say it updated successfully it will not update.

Reference link

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.