views:

59

answers:

3

I've an arraylist having 30000 items in it, what's the best way of creating a text file on the fly from an ASP.NEt page? Currently I'm using the code below but it times out with large data,

Using fileStr As New FileStream(sFileName, FileMode.Create, FileAccess.Write)
 Using writer As New StreamWriter(fileStr)
   writer.WriteLine("Error Messages")
   For d As Integer = 0 To ar.Count - 1
      writer.WriteLine(ar(d).ToString())
      sErrMsg += "<tr><td class='errgrid'>><td class='errgrid'>" + ar(d).ToString() + "</td><tr>"
   Next
   writer.Close()
 End Using
 fileStr.Close()
End Using
A: 

Well i think this is an easy way:

Dim fs As FileStream = File.Create(path)
        Dim info As Byte() = New UTF8Encoding(True).GetBytes("This is some text in the file.")

        ' Add some information to the file.
        fs.Write(info, 0, info.Length)
        fs.Close()

http://msdn.microsoft.com/en-us/library/d62kzs03.aspx

Regards,

Shoaib Shaikh
A: 

Well first off I'd say take this out of the ASP .Net Page and put it as something that runs on the server. Then create that file on the server then just have the user download the file or do whatever you need to do with it.

msarchet
A: 

I assume sErrMsg is a String variable. You really want to change that into a StringBuilder.

Mattias S
Also I'd changed the way it's working, as Joel said writing 30,000 items to an html page is bad.
JJK