Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 972601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:09:01+00:00 2026-05-16T03:09:01+00:00

We are using it to return a file for an export. When we run

  • 0

We are using it to return a file for an export. When we run this export on a lot of records, it takes close to 10 minutes to run. Here is a code snippet of the code that actually calls the File() method and returns the result.

Public Function Export(ByVal ID As Integer) As FileContentResult
  Dim str As String = String.Empty
  Dim data() As Byte
  Dim r As New ExportResult
  Dim Test As New TestConnection(WebUtil.UserToken)

  'This line is important coz IE download was prevented without this.
  ControllerContext.HttpContext.Response.ClearHeaders()

  r = Test.ExportFile(ID)
  data = Encoding.ASCII.GetBytes(r.ResponseString)

  Return File(data, "text/plain", r.DefaultFileName)

End Function

The actual ExportFile method takes in an ID, calls another method, which gets a bunch of records from the database, performs a bunch of calculations on each row, and then creates a StringBuilder, and for each row populates the StringBuilder and then pops it into a List(Of String), after doing a .ToString(). Then this method returns the List(Of String) to the ExportFile method, and this method creates another StringBuilder, appends all the Strings from that list, converts it to one large String, and sets it to the ResponseString property of the result (‘r’ in the code above).

So that’s how it works. Is there anyway to speed this process up, like, a lot?

-Scott

Edit: More Code

Public Function ExportFile(ByVal ID As Integer) As ExportResult
            Dim result As New ExportResult
            Dim s As New StringBuilder

            'Get all Records
            Dim dt As New DataTable
            Using dal As New SQL
                dal.Parameters.AddWithValue("@ID", ID)
                dal.Execute("[dbo].[uspGet]", dt)
                dal.Parameters.Clear()
            End Using

            Dim dataobj As New DataObj(dt, ID)

            'Create FileName
            If dt.Rows.Count > 0 Then
                Dim StartDate As DateTime = DateTime.Parse(dt.Rows(0).Item("StartDate"))
                Dim EndDate As DateTime = DateTime.Parse(dt.Rows(0).Item("EndDate"))
                result.DefaultFileName = String.Format("HMDA_{0}_{1}.dat", String.Format("{0:MMyyyy}", StartDate), String.Format("{0:MMyyyy}", EndDate))
            End If

            'Add Title Line
            s.AppendLine(dataobj.CreateTitleLine())

            'Add all Record Lines
            Dim records As List(Of String) = dataobj.CreateRecordLines()
            Dim last As Integer = records.Count - 1
            For i = 0 To last
                If i = last Then
                    s.Append(records(i))
                Else
                    s.AppendLine(records(i))
                End If
            Next

            result.ResponseString = s.ToString

            Return result
End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:09:01+00:00Added an answer on May 16, 2026 at 3:09 am

    How performant is your SQL? I’d start checking there for your problems.

    Then consider how big your file is. The data still needs to be downloaded at the client.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this code to return a FileContentResult with an MSI file for the
I've created a sql dump file using pg_dump. This export file contains functions which
So, I have this code that grabs a bunch of data from the database,
I have this function I am using to decrypt values that works fine on
I'm using ubuntu 64-bit and trying to run a .asm file on NASM. But
I have a struct that I'd like to export to a file, and then
I have a array that I am writing to a file using var_export() .
I need to display the content of another page from a function using return.
In ASP.NET MVC3, when a view model is passed into a view using return
I am using the return from the following call as the datasource for a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.