Export Table into textfile

296
2
09-23-2010 09:46 AM
ludoDupuis
New Contributor
Hi folks,
I am wondering what type of exporter should I use to export tables (as standalonetable) to get file.txt

There is a lot of exporter to export into jpeg, tiff etc... and  there is a possibility to select txt format in the Exportdialog. Unfortunately  I do not find any solution to write a macro with VB to create a txt file of the attribute table ...

Cheers
and thank you
L.
0 Kudos
2 Replies
JamesCrandall
MVP Frequent Contributor
Hi folks,
I am wondering what type of exporter should I use to export tables (as standalonetable) to get file.txt

There is a lot of exporter to export into jpeg, tiff etc... and  there is a possibility to select txt format in the Exportdialog. Unfortunately  I do not find any solution to write a macro with VB to create a txt file of the attribute table ...

Cheers
and thank you
L.



The only example I have on hand at the moment will create a comma-delimited CSV/.txt file for an ADO.NET DataTable, but you could very well replace this with the rows in a standalone Table in ArcGIS.

Anwyay, hope this helps!

james


untested

Dim CSVFile As System.IO.StreamWriter
CSVFile = New System.IO.StreamWriter("C:\FileNameToCreate.txt")

Dim sb As New System.Text.StringBuilder
sb = New System.Text.StringBuilder
CSVFile.WriteLine("Field1, Field2, Field3, Field4, Field5")

Using CSVFile
     For Each r As DataRow In theADONetDataSet.Tables(0).Rows 
           sb = New System.Text.StringBuilder
           sb.Append((r("Field1")) & "," _
                      & (r("Field2")) & "," _
                      & (r("Field3") & "," _
                      & (r("Field4")) & "," _
                      & (r("Field5"))))
            
           CSVFile.WriteLine(sb.ToString)
      Next
 End Using
0 Kudos
ThavitinaiduGulivindala
Occasional Contributor
Hi,

I dont know if there is any method that exports the data from Stand alone table to text file at a go.
But, ESRI has a way to create text file using TextFileWorkspaceFactory class.

Following is the example from EDN to open text file as a Table. Hence I feel, you can create text file as Table and load the Data from source table into Text file.


// Create a new TextFile workspacefactory and open the workspace
IWorkspaceFactory workspaceFactory = new TextFileWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspace workspace = workspaceFactory.OpenFromFile(
    "c:\\temp\\testing", 0);

// Cast for IFeatureWorkspace
ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)
    workspace;

// Open a table
ESRI.ArcGIS.Geodatabase.ITable oledbTable = featureWorkspace.OpenTable("farms.txt");

http://resources.esri.com/help/9.3/arcgisengine/dotnet/c68303f6-8360-40c0-9faa-e0efdcc44c86.htm
0 Kudos