小编Pol*_*era的帖子

文件上传读取到内存并用作文本文件 - 有更好的方法吗?

我有一个Intranet托管的Web应用程序,用户将上传一个包含5列空格分隔数据的文本文件.我不想保存文件,所以我想在内存中使用它.我在网上尝试了许多不同的例子,但都没有.最后,一位同事告诉我如何做到这一点.这是代码,我想知道是否有更好的方法来做到这一点.最后,我想要的是一种将数据链接到gridview或转发器以便查看和以后存储到数据库(SQL Server)的方法.

上传文件asp标签ID是SurveyFileUpload
SurveyDate是一个asp:输入字段

Int32 fileLen = SurveyFileUpload.PostedFile.ContentLength;

// Create a byte array to hold the contents of the file.
Byte[] buffer = new Byte[fileLen];

// Initialize the stream to read the uploaded file.
Stream s = SurveyFileUpload.FileContent;

// Read the file into the byte array.
s.Read(buffer, 0, fileLen);

// Convert byte array into characters.
ASCIIEncoding enc = new ASCIIEncoding();
string str = enc.GetString(buffer);
testReadFile(str, db_surveyDate.Text);

protected void testReadFile(string inFileString, string inSurveyDate)
{
    string[] lines = inFileString.Split('\n');
    curFileListing.InnerHtml = ""; …
Run Code Online (Sandbox Code Playgroud)

c# linq asp.net streaming file-upload

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net ×1

c# ×1

file-upload ×1

linq ×1

streaming ×1