在 .NET 中创建文件的最快且有效的方法
我有一个包含 30000 个项目的数组列表,从 ASP.NEt 页面动态创建文本文件的最佳方法是什么?目前我正在使用下面的代码,但它会因大数据而超时,
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设 sErrMsg 是一个字符串变量。您确实想将其更改为 StringBuilder。
I assume sErrMsg is a String variable. You really want to change that into a StringBuilder.
嗯,我认为这是一个简单的方法:
http://msdn.microsoft.com /en-us/library/d62kzs03.aspx
问候,
Well i think this is an easy way:
http://msdn.microsoft.com/en-us/library/d62kzs03.aspx
Regards,
首先,我想说将其从 ASP .Net
Page
中取出,并将其作为在服务器上运行的内容。然后在服务器上创建该文件,然后让用户下载该文件或执行您需要对其执行的任何操作。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.