1

I have been asked to rewrite a VBA tool into a C# application, but came across a line of code that I am not sure how to do the same thing in C# as it is done in VBA.

What would be the C# equivalent of the DoCMD.TransferText command to export data to a tab delimited file?

Here is the code currently being used in VBA:

DoCmd.TransferText acExportDelim, "TEMP_Tracker Export Specification", "TEMP_Tracker", "\\BulkInsert\UtilityNotes.txt", True 

Any help on this is greatly appreciated :-)

  • The answer is not a one-liner. It will likely involve creating a text file and writing the output line by line to it. What's the definition of your output template `TEMP_Tracker Export Specification`? – Martin Nov 19 '20 at 13:29
  • How are you accessing your tables (like `TEMP_Tracker`) in your C# solution? Are you pulling them into `DataSet`s? – Martin Nov 19 '20 at 13:30
  • Here is an entire article on this: (https://social.msdn.microsoft.com/Forums/office/en-US/a12e3b6e-3c8c-41a2-a210-7c53a5e5734c/docmdtransfertext-performance?forum=accessdev) – Ryan Wilson Nov 19 '20 at 13:31

1 Answers1

0

Sorry, there's nothing built-in.

The .NET Framework contains a class for reading delimiter-separated text files (TextFieldParser, it's in the Microsoft.VisualBasic.FileIO namespace but works with C# as well), but there's nothing built-in for writing them.

Your best bet would be to look for a CSV export library for .NET, or just write the code yourself: If the values you want to write are free of field and line delimiter characters, it's no more than a simple loop through your data source, adding the values to a StringBuilder and then writing it with File.WriteAllText. There are various sample implementations here on StackOverflow, e.g. this one.

Heinzi
  • 167,459
  • 57
  • 363
  • 519