We had a process that split large files into smaller files be reading and writing line by line. This fixed the out of memory exceptions we were having, but it took hours to complete. I rewrote this method, so it is way faster, and doesn't cause memory exceptions.

vb Code:
  1. Private Function SplitFile( _
  2.     ByVal inputFileName As String, ByVal outputFileName As String, ByVal numberOfFiles As Integer) _
  3.     As List(Of String)
  4.         Dim returnList As New List(Of String)
  5.         Try
  6.             Dim outputFileExtension As String = IO.Path.GetExtension(outputFileName)
  7.             outputFileName = outputFileName.Replace(outputFileExtension, "")
  8.             Dim sr As New IO.StreamReader(inputFileName)
  9.             Dim fileLength As Long = sr.BaseStream.Length
  10.             Dim baseBufferSize As Integer = CInt(fileLength \ numberOfFiles)
  11.             Dim finished As Boolean = False
  12.             Dim fileCount As Integer = 1
  13.             Do Until finished
  14.                 Dim bufferSize As Integer = baseBufferSize
  15.                 Dim originalPosition As Long = sr.BaseStream.Position
  16.                 'find line first line feed after the base buffer length
  17.                 sr.BaseStream.Position += bufferSize
  18.                 If sr.BaseStream.Position < fileLength Then
  19.                     Do Until sr.Read = 10
  20.                         bufferSize += 1
  21.                     Loop
  22.                     bufferSize += 1
  23.                 Else
  24.                     bufferSize = CInt(fileLength - originalPosition)
  25.                     finished = True
  26.                 End If
  27.                 'write the chunk of data to a buffer in memory
  28.                 sr.BaseStream.Position = originalPosition
  29.                 Dim buffer(bufferSize - 1) As Byte
  30.                 sr.BaseStream.Read(buffer, 0, bufferSize)
  31.                 'write the chunk of data to a file
  32.                 Dim outputPath As String = outputFileName & fileCount.ToString & outputFileExtension
  33.                 returnList.Add(outputPath)
  34.                 My.Computer.FileSystem.WriteAllBytes( _
  35.                 outputPath, buffer, False)
  36.                 fileCount += 1
  37.             Loop
  38.         Catch ex As Exception
  39.             Console.Write(ex.ToString)
  40.         End Try
  41.         Return returnList
  42.     End Function