Login / Register  search  syndication  about

          Ryan Farley's Blog

Ryan Farley on .NET Development with a focus on CRM Development for SalesLogix

Exporting a DataGrid to a CSV File

Along the same lines as my posts on exporting a SalesLogix DataGrid (well, exporting the Recordset behind the grid) to Excel, Michael Cessna from SalesLogix shared this quick bit of code for dumping a Recordset to a CSV file (posted in the SalesLogix Business Partner newsgroups)

Option Explicit

Const adClipString = 2

' ExportRecordsetToCSV objRS, "C:\Test.csv", True, True
Sub ExportRecordsetToCSV(Recordset, FileName, IncludeFieldNames, MoveFirst)

    Dim objFSO
    Dim objFile
    Dim iFieldCount
    Dim oFields()
    Dim strHeader

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.CreateTextFile(FileName, True)

    If MoveFirst Then
       Recordset.MoveFirst
    End If

    If IncludeFieldNames Then
       Redim oFields(Recordset.Fields.Count)
       For iFieldCount = 0 To Recordset.Fields.Count -1
           oFields(iFieldCount) = Recordset.Fields(iFieldCount).Name
       Next
       strHeader = Join(oFields, Chr(9))
       objFile.WriteLine(strHeader)
    End If

    objFile.Write(Recordset.GetString(adClipString))
    objFile.Close()

    Set objFile = Nothing
    Set objFSO = Nothing

    If MoveFirst Then
       Recordset.MoveFirst
    End If
End Sub

What's This?
  
Bookmark and Share

About Ryan Farley

   Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix since 2001 and believes in sharing with the community. He loves C#, Javascript, Python, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

View the SalesLogix Mobile Seveloper Series
View the SalesLogix SData Developer Series
View the Git for the SalesLogix Developer series



Related Content
   Delivering Data & Schema in SalesLogix Bundles
If you've had any exposure to SalesLogix, you'll have used a bundle. Bundles are great, but when
Posted on Apr 24, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Using a Test Plan
So you have approved the Statement of Work (SOW) for some modifications and are awaiting the delivery of
Posted on Mar 13, 2014 by George Jensen to George Jensen's Blog
 
   Creating a Saleslogix Ticket Pretty Prefix and Suffix in External Applications
Some entities in SalesLogix, such as Tickets, use a "pretty key" as an easier to use value to r
Posted on Feb 28, 2014 by Ryan Farley to Ryan Farley's Blog
 
   Evaluating strings in C# Code snippets
When checking for two (or more) different values for a property in a code snippet, you can't simply l
Posted on Dec 13, 2013 by Jason Buss to Jason Buss' Blog
 
   Updates to the SalesLogix Mobile Developer Toolkit
I've released some updates to the SalesLogix Mobile Developer Toolkit. This new release adds some fix
Posted on Apr 10, 2013 by Ryan Farley to Ryan Farley's Blog
 
Comments

 

Clancy said:

I'm rather new to SLX development but I've noticed that in a lot of vendor code and in a great many samples developers don't type their variables (as with above) - why is that???
March 3, 2005 6:28 AM
 

Ryan Farley said:

Hi Clancy,

Because SLX uses VBScript, not VB. In VBScript you cannot type your variables (You'll get an error if you do).

-Ryan
March 3, 2005 6:40 AM
 

Clancy said:

Doh! I knew that. I guess my mind just gets tripped up moving back and forth between legecy and VB Script..
March 3, 2005 7:40 AM

Leave a Comment

(required)  
(optional)
(required)  
Add
All contents Copyright © 2014 Customer FX Corporation
Customer FX Corporation
2324 University Avenue West, Suite 115
Saint Paul, Minnesota 55114
Tel: 800.728.5783

  Follow @CustomerFX on twitter
Follow the best news, tips, and articles
  Subscribe to Customer FX on youtube
Watch SalesLogix tutorial videos from Customer FX
Login / Register