The OneStream Community is temporarily frozen until June 29th due to the ongoing maintenance. Please read the blog post here to learn more.

Forum Discussion

Ashok's avatar
Ashok
New Contributor III
2 years ago
Solved

Any way to export imported source documents from OneStream to an External folder?

hey All, I have request to dump out all the imported source documents to a central location. Not sure if it is possible. Looking for some information on Where these files/documents are stored w...
  • MarcusH's avatar
    2 years ago

    The source documents are held in the table StageArchivesInformation. I haven't downloaded the source files but I think you will need something like this (saves the source file to the user's temporary folder):

    Dim profileKey As String = si.WorkflowClusterPk.ProfileKey.ToString
    Dim scenarioKey As Integer = si.WorkflowClusterPk.ScenarioKey
    Dim timeKey As Integer = si.WorkflowClusterPk.TimeKey
    
    Dim sql As New Text.StringBuilder
    sql.AppendLine("SELECT SourceFileName, SourceFileBytes")
    sql.AppendLine("FROM StageArchivesInformation With(NOLOCK)")
    sql.AppendLine(String.Format("WHERE Wfk = '{0}'", profileKey))
    sql.AppendLine(String.Format("AND Wsk = {0}", scenarioKey))
    sql.AppendLine(String.Format("AND Wtk = {0}", timeKey.ToString))
    
    Dim SourceFileName As String = String.Empty 
    Dim fileBytes As Byte() 
    Using dbConnApp As DbConnInfo = BRApi.Database.CreateApplicationDbConnInfo(si)
        Using dt As DataTable = BRApi.Database.ExecuteSql(dbConnApp, sql.ToString, False)
            If (dt IsNot Nothing) AndAlso (dt.Rows.Count > 0) Then
                For Each dr As DataRow In dt.Rows
                    SourceFileName = dr("SourceFileName")
                    fileBytes = dr("SourceFileBytes")
                Next
            End If
        End Using
    End Using
    
    BRApi.Utilities.SaveFileBytesToUserTempFolder(si, si.UserName, SourceFileName, fileBytes)