开发者

Read the first line of a file from memory

开发者 https://www.devze.com 2023-01-13 10:09 出处:网络
I have a tab delimited text file that I need to 开发者_StackOverflowupload to a secure folder for SSIS to import into SQL Server.The file will be uploaded by an external user VIA a web app.

I have a tab delimited text file that I need to 开发者_StackOverflowupload to a secure folder for SSIS to import into SQL Server. The file will be uploaded by an external user VIA a web app.

My challenge is that I need to check this file for some things before I am allowed to let it go to the secure folder. Namely I need to make sure the user has a specific column.

I can do this if I save the file to a folder in the web app. However the nature of the data in the file is such that we do not wish to place this file anywhere other then the secured folder. I also can not place it directly to this folder because the SSIS package is set to trigger as soon as the file shows up there.

What I need to do is find a way, if there is one, to parse the file in memory and if it passes all the checks, upload it to the secure folder.

I'm using C#.NET and the FileUpload Control.

My search so far has included all kinds of information but they all require saving the file somewhere first and then working with it.

Thank you so much for your time. If anybody can point me to an object or some code I can check out I would be most grateful.


Rather than calling SaveAs, use the FileContent property to access the contents of the file as a Stream, then you can do whatever processing is required before you save it manually.

For example, something like this:

string data;

using(StreamReader reader = new StreamReader(fileUpload.FileContent))
{
    data = reader.ReadToEnd();
}

The data variable now contains the contents of the file as a string. You can do whatever processing you like, then save it (or not) to the appropriate location.

0

精彩评论

暂无评论...
验证码 换一张
取 消