This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

M-Files to Sharepoint export

Greetings, 

 

We are having some troubles importing a document into sharepoint that has been downloaded by the folowing script in a certain state. 

 

 

Option Explicit 

  

'ours folder...  

Dim folderName, BoardDecisionName 

BoardDecisionName = PropertyValues.SearchForProperty(1079).TypedValue.DisplayValue 

folderName = "C:\M-Files_Export\Board_Decision_Approved\" 

                 

' Create a filesystemobject to help working with files. 

Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject") 

  

' Get a reference to the folder. 

Dim strTempFolderPath: strTempFolderPath = objFSO.GetAbsolutePathName(folderName) 

  

' Get the files for the current objver. 

Dim objFiles: Set objFiles = Vault.ObjectFileOperations.GetFiles(ObjVer) 

  

  

' Iterate over the files and download each in turn. 

Dim intCounter, objFile 

For intCounter = 1 To objFiles.Count 

                                

                ' Which file are we working with? 

                Set objFile = objFiles.Item(intCounter) 

                     

                ' Where can we download it? 

                Dim strTemporaryFilePath: strTemporaryFilePath = objFSO.BuildPath(strTempFolderPath,ObjVer.ID) & "_" & BoardDecisionName & "." & objFile.Extension 

  

                ' Download the file. 

                Vault.ObjectFileOperations.DownloadFile objFile.ID, objFile.Version, strTemporaryFilePath 

 ' Define Propertie for export 

Dim oDocID : oDocID = PropertyValues.SearchForProperty( 1082 ).TypedValue.DisplayValue 

Dim strXML : strXML = Vault.ObjectPropertyOperations.GetPropertiesAsXML(ObjVer) 

' Create a FileSystemObject 

Set objFSO=CreateObject("Scripting.FileSystemObject") 

' Provide file path 

Dim outFile : outFile = "C:\M-Files_Export\Board_Decision_Approved\XML\" & ObjVer.ID & "_" & BoardDecisionName & ".xml" 

' Setting up file to write 

Set objFile = objFSO.CreateTextFile(outFile,True) 

' Write to file 

objFile.WriteLine strXML 

' Cleanup 

objFile.Close 

Next 

 

The script downloads a PDF and XML file, those two files have the same name. We need to upload/import the pdf document into a sharepoint library and using the XML file we need to fill in some of the columns (exp. Company, Last Modified and Last Modified by).  

 

Is there a solution for this? We tried using a Powershell script below. 

 

#Load SharePoint CSOM Assemblies 

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" 

Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" 

   

#Set parameter values 

 

$SiteURL"Library link" 

$ListName="Library" 

$XMLFile ="C:\M-Files_Export\Board_Decision_Approved\XML\722_Test.xml" 

$Username = "hidden" 

$Password = "hidden" 

Try{ 

    #Get Credentials to connect 

    #$Cred= Get-Credential 

    

    #Setup the context 

    #$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) 

    Connect-PnPOnline -Url $siteUrl -UseWebLogin 

    #$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, (ConvertTo-SecureString $Password -AsPlainText -Force)) 

     

       

    #Get the web & List objects 

    $Web = $Ctx.Web 

    $Ctx.Load($Ctx.Web) 

    $List = $Web.Lists.GetByTitle($ListName) 

    $Ctx.ExecuteQuery() 

 

    #import xml file 

    [xml]$ProjectXmlFile = Get-Content $XMLFile 

   

    #Iterate through each "Project" node of the XML file 

Foreach ($XMLProject in $ProjectXmlFile.properties.prop) 

    { 

         

        #Add New List Item 

        $ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation 

        $NewProject = $List.AddItem($ListItemInfo) 

 

        #Map XML fields to SharePoint Online List Fields - Internal Name 

       # $NewProject["Name"] = $XMLProject.0 

        #$NewProject["Izmijenjeno"] = $XMLProject.21 

       # $NewProject["Izmijenio"] = $XMLProject.23 

        #$NewProject["Company"] = $XMLProject.1144 

        #$NewProject["DocumentType"] = $web.100 

        #$NewProject["Function"] = $XMLProject.1059 

        $NewProject["Naziv"] = "ic-vin-import-70828.txt" 

        $NewProject["Izmijenjeno"] = "Test1" 

        $NewProject["Izmijenio"] = "Test2" 

        $NewProject["Company"] = "Test3" 

        $NewProject["DocumentType"] = "Test4" 

        $NewProject["Function"] = "Test5" 

     

        $NewProject.Update() 

   

        Write-Host "M-Files document has been Imported to the DMS List!" 

    } 

    $Ctx.ExecuteQuery() 

} 

Catch { 

        write-host -f Red "Error Importing XML Data into List!" $_.Exception.Message 

} 

 

In the Powershell script there isnt any connection to the PDF document yet because we have some troubles connecting to the sharepoint and having some troubles mapping the XML generated file from M-Files. (We are not quite sure how to map it. 

 

 Has anyone had simmilar experience or has had solution for this? We need to use this powershell script for our use case.