Hola jóvenes laneros.
Ya encontré la solución, después de explorar varias opciones, encontré 2 soluciones
Opción 1: leer Stream y reescribir otro sin las lineas que necesito, OJO, aquí se debe tener en cuenta la codificación para mi caso era ANSI UNIX no ANCI PC
Opcion 2: Recorrer el Stream, leyendo el header del Stream en la que se puede saber el tipo de archivo y el nombre,
después de eso eliminar el header y footer del Stream y escribir nuevamente el STREAM sin esas lineas
byte[] data = ToByteArray(fileStream);
string content = encoding.GetString(data);
int delimiterEndIndex = content.IndexOf("\r\n");
if (delimiterEndIndex > -1)// es mayor a -1 si la codificacion es la correcta para el indexOf del delimitador
{
string delimiter = content.Substring(0, content.IndexOf("\r\n"));
// mira el Content-Type, es decir el tipo de archivo
Regex re = new Regex(@"(?<=Content\-Type
(.*?)(?=\r\n\r\n)");
Match contentTypeMatch = re.Match(content);
// mira el nombre del archivo
re = new Regex(@"(?<=filename\=\"")(.*?)(?=\"")");
Match filenameMatch = re.Match(content);
if (contentTypeMatch.Success && filenameMatch.Success)
{
this.ContentType = contentTypeMatch.Value.Trim();
this.Filename = filenameMatch.Value.Trim();
int startIndex = contentTypeMatch.Index + contentTypeMatch.Length + "\r\n\r\n".Length;
byte[] delimiterBytes = encoding.GetBytes("\r\n" + delimiter);
int endIndex = IndexOf(data, delimiterBytes, startIndex);
int contentLength = endIndex - startIndex;
byte[] fileData = new byte[contentLength];
Buffer.BlockCopy(data, startIndex, fileData, 0, contentLength);
t
his.FileContents = fileData;
}
Lo importante aquí es
this.ContentType = contentTypeMatch.Value.Trim();
this.Filename = filenameMatch.Value.Trim();
this.FileContents = fileData;
Gracias