Forum Discussion

Mikki's avatar
Mikki
New Contributor III
1 day ago

How to read csv file from Documents/users folder?

Hi,

I have been trying to read a csv file that is in Documents/Users/userxxxx folder. Not able to make it work. Getting an error.

Below is the code

Dim FileName As String = args.NameValuePairs.XFGetValue("Param1", String.Empty)
            Dim sourceFolder As String = $"Documents/Users/{StringHelper.RemoveSystemCharacters(si.UserName,False,False)}"
            Dim fullPath = sourceFolder & "/" & "abc.csv"
 

Below is the error

Could not find file 'P:\Program Files\OneStream Software\OneStreamAppRoot\OneStreamApp\Documents\Users\userxxxx\abc.csv'.

Any idea why this is not working?

Thank you,

Mikki

 

2 Replies

  • Mikki's avatar
    Mikki
    New Contributor III

    Hi Sam,

    I am trying to read the file as datatable so I can load to table. I guess then I have to find a way to export the data to File Share and read it from there. This is something that is one off process that we are going to need to do as part of upgrade.  

    Thank you,

    Mikki

  • sameburn's avatar
    sameburn
    Icon for OneStream Employee rankOneStream Employee

    Hi Mikki​ 

    Documents/Users in OneStream represents the Application Database e.g.

     

     

     

     

    This means the file is stored in a database table and not a real file path.  This is why you are receiving an error trying to use a UNC path.  If you search GetFile in snippets you will see this BRApi example

    It is not clear what you are trying to do with the file itself.  But here is a working example to get the file as bytes from Documents/Users using BRApi's available

    Dim folderFullName As XFFolderEx = BRApi.FileSystem.GetFolder(si, FileSystemLocation.ApplicationDatabase, Path.Combine("Documents/Users", StringHelper.RemoveWhiteSpace(si.UserName)))
    Dim objXFFileEx As XFFileEx = BRApi.FileSystem.GetFile(si, FileSystemLocation.ApplicationDatabase, Path.Combine(folderFullName.XFFolder.FullName, "YourFileName.csv"), True, True)
    Dim fileBytes As Byte() = objXFFileEx.XFFile.ContentFileBytes()

    Hope this helps

    Sam