Forum Discussion

ssmith-nova's avatar
ssmith-nova
New Contributor III
9 months ago

Exporting data to a Flat File in the OneStream File System using C#

This seems like it should be a no brainer, but I've spent a couple hours trying to figure it out and googling for a solution and I have nothing.

I am trying to export data to a file, but my BR is written in C#.  I can do it with no issues in VB: 

'Prepare the Extract File path
Dim configSettings As AppServerConfigSettings = AppServerConfig.GetSettings(si)
'Data management extract location
Dim folderPath As String = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, True, configSettings.FileShareRootFolder, si.AppToken.AppName) & "\" & DateTime.UtcNow.ToString("yyyyMMdd") & "\Extracts"
'if the diirectory does not exist create.
If Not Directory.Exists(folderPath) Then Directory.CreateDirectory(folderPath)
' full path and file name for extract
Dim filePath As String = folderPath & "\AppTypes.xml"
'if file already exists
If File.Exists(filePath) Then File.Delete(filePath)
File.WriteAllText(filePath, outer.accountRecs.ToString);

I tried to convert it to C#:

//Prepare the Extract File path
AppserverConfigSettings configSettings = AppServerConfig.GetSettings(si);
// Data management extract location
string folderPath = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, true, configSettings.FileShareRootFolder, si.AppToken.AppName) + "\\" +  DateTime.UtcNow.ToString("yyyyMMdd") & "\\Extracts";
					
// if the diirectory does not exist create.
if (!Directory.Exists(folderPath))
{
    Directory.CreateDirectory(folderPath);
}
					
// full path and file name for extract
string filePath = folderPath + "\\TestSAP.txt";
					
//' if file already exists
if (File.Exists(filePath))
{
    File.Delete(filePath);
}
File.WriteAllText(filePath, outer.accountRecs.ToString);

But I am getting an error:

1) Error at line 148:  The type or namespace name 'AppserverConfigSettings' could not be found (are you missing a using directive or an assembly reference?) 

I have all of the OneStream libraries included.  Does anyone know what I am doing wrong or have a sample of a writing a file to the OneStream File System using C#?

Thanks

 

 

  • C# is case sensitive.  Use AppServerConfigSettings instead of AppserverConfigSettings.

    I also removed the unnecessary If statements:

    AppServerConfigSettings configSettings = AppServerConfig.GetSettings(si);
    string folderPath = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, true, configSettings.FileShareRootFolder, si.AppToken.AppName) + "\\" + DateTime.UtcNow.ToString("yyyyMMdd") + "\\Extracts";
    Directory.CreateDirectory(folderPath);
    string filePath = folderPath + "\\AppTypes.xml";
    File.Delete(filePath);
    File.WriteAllText(filePath, outer.accountRecs.ToString());
    

     

  • RobbSalzmann's avatar
    RobbSalzmann
    Valued Contributor II

    C# is case sensitive.  Use AppServerConfigSettings instead of AppserverConfigSettings.

    I also removed the unnecessary If statements:

    AppServerConfigSettings configSettings = AppServerConfig.GetSettings(si);
    string folderPath = FileShareFolderHelper.GetDataManagementExportUsernameFolderForApp(si, true, configSettings.FileShareRootFolder, si.AppToken.AppName) + "\\" + DateTime.UtcNow.ToString("yyyyMMdd") + "\\Extracts";
    Directory.CreateDirectory(folderPath);
    string filePath = folderPath + "\\AppTypes.xml";
    File.Delete(filePath);
    File.WriteAllText(filePath, outer.accountRecs.ToString());