Spliting Rows of CSV file to new CSV files

shuvo2k6

New member
Joined
Jun 6, 2017
Messages
1
Programming Experience
Beginner
Spliting Rows of CSV file to new CSV files.

I am using ASP.NET MVC5 with C# on Visual Studio 2015.
 
Basically what you're going to need to do is when the user uploads the file to the webserver you'll need to save it in a directory that has IIS read & write permissions. Then you can use a StreamReader to read the file line by line (might want to keep the first line in a variable if there's a header, so you can write it out to all of the files) and from there as you read in a line you write it out to a file, if it's a certain number of lines per file you're doing then keep a running counter (Long) and when the desired number is reached you close out the StreamWriter, create a new file, and continue the loop. If it's a sorting thing you can set up multiple StreamWriter's and using a Select Case or a series of If ElseIf's you can write to the specific file. When the end of the StreamReader is hit simply close out & dispose of the StreamReader and all the StreamWriters.
I can guide you on Console, WinForms, WPF, and ASP.Net; however I'm not very familiar with MVC so I'd have to look up how you would have a controller handle files on the webserver.
 
Back
Top Bottom