I've been struggling with this for a while. I created a utility that allows you to open .TXT files. These text files contain PCL (Print Command Language). When I import a new file, it is being truncated by a \0 (NULL Terminator character). Because PCL files contain graphic images randomly throughout everything I import is truncated at the first bitmap image because the bitmap images start with NULL.
This is the exact issue as seen here: Displaying Raw Data From Image File Using TextBox or RichTextBox?
Unfortunately I can't comment on this thread though because of my low (newbie) reputation (need 15 rep). Also can't paste a screenshot (need 10 rep).
Here is how Notepad++ displays the information:
Here is how my RichTextBox displays this same information:
Here is why this is a problem (Zoomed out):
The raster data is right between two sections of data I need (The PCL). All of the information below the raster data won't pull in.
Here is what I have tried (Note: I am using a custom RichTextBox, but this shouldn't affect anything since it's just a RichTextBox with Drag/Drop functionality):
byte[] bytes = new byte[2048];
string data = System.Text.Encoding.ASCII.GetString(bytes);
dragDropRichTextBox1.Text = data.Replace("\0", @"1");
This just causes a chain of 2048 number "1" characters with none of the text file's data pulling in. Any help is much appreciated.
Whatever I do, I would like to preserve my current drag/drop functionality:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PCL_Utility
{
public class DragDropRichTextBox : RichTextBox
{
public DragDropRichTextBox()
{
this.AllowDrop = true;
this.DragDrop += DragDropRichTextBox_DragDrop;
}
void DragDropRichTextBox_DragDrop(object sender, DragEventArgs e)
{
//string[] fileText = e.Data.GetData(DataFormats.FileDrop) as string[];
string[] fileText = e.Data.GetData(DataFormats.FileDrop) as string[];
if (fileText != null)
{
foreach (string name in fileText)
{
try
{
this.AppendText(File.ReadAllText(name) + "\n -------- End of File -------- \n\n");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
}
}