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 T开发者_StackOverflow中文版o 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
I assume sErrMsg is a String variable. You really want to change that into a StringBuilder.
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,
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.
精彩评论