I had a Visual Basic.NET ASP.NET application that was digesting a text input file 3 megabytes in size with 30,000 lines. It was taking 20 minutes to complete! I began looking at different factors. The actual upload went like this:

Code:

fileMyFile.PostedFile.SaveAs(Server.MapPath(".") & TempCSVFilename)

and it used a System.Web.UI.HtmlControls.HtmlInputFile control on the web page. It completed within one second. So I knew that was not the problem.

It seemed that the Regex and Try/Catch statements were also not the problem. The real speed up came when I took out a String append step. I had a string called "Textboxstring" to which I kept appending message data. It would eventually reach about 40,000 lines. At the end, I would send this text data to the results web page.

My savior was the Stringbuilder class! My original code was like this: