Hi guys,
I made a post not long ago.
Instead of working on my main program i decided to work on a smaller program for testing.
my problem i am having atm, is if i use a file sig i put hard coded in my code.. it works... but if i tell it to use my string value... it doesnt like it... even though the value is exactly the same...
I will post my code, and then explain a little more at the end of the post:
My XML File:
="1.0"
<Filesigs>
<Images>
<sig name = "jpg">FF-0D-FF-E0</sig>
<sig name = "jpg">FF-D8-FF-E8</sig>
<sig name = "png">89-50-4E-47-0D-0A-1A-0A</sig>
<sig name = "gif">47-49-46-38-37-61</sig>
<sig name = "gif">47-49-46-38-39-61</sig>
<sig name = "tiff">49-20-49</sig>
<sig name = "tiff">49-49-2A-00</sig>
<sig name = "bmp">42-4D</sig>
</Images>
</Filesigs>
my program code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml.Linq;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"C:\Users\Alan\Desktop\Koala.bob", FileMode.Open);
byte[] buffer = new byte[20];
fs.Read(buffer, 0, 20);
string hex = BitConverter.ToString(buffer);
textBoxStoredExtension.Text = (Path.GetExtension(@"C:\Users\Alan\Desktop\Koala.bob"));
string storedFileSig = (hex);
textBoxStored.Text = hex;
XDocument myDoc = XDocument.Load("FileSigs.xml");
IEnumerable<String> result = from FileSigs in myDoc.Elements()
from Images in FileSigs.Elements()
from sigs in Images.Elements()
where (storedFileSig.Contains(sigs.Value))
select sigs.Attribute("name").Value;
foreach (String r in result)
{
textBoxXMLExtension.Text = r;
}
}
}
}
Ok,
as you can see, my program takes the first 20 bytes of the file.
converts to hex and stores in a string called "hex"
it then gets the file extension of the file and displays it in a text box for now. (will be used further later but not important at the moment)
it then goes to the XML file and checks through the XML file until it finds a value that the "hex" contains.
so... when i am testing... i am using a "image.bob" file... when i read it in.. it returns a 20 byte hex calue with -'s between each byte...
so when i run it: i am given FF-D8-FF-E0-00-10-4A-46-49-46-00-01-01-01-00-60-00-60-00-00 for the 20 bytes from the "image.bob" file.
it then should check the XML and see that the first 1 in my XML file matches as the 20 bytes contains "FF-D8-FF-E0".
because it matches. it should then display .jpg (taken from the XML file) and display it in a text box below the text box that displays the ".bob" file extension from the start. (this WONT work when i use String Hex... but as you can see from my code i have commented out //string storedFileSig = ("FF-0D-FF-E0");.... which does work...
then I want it to display the file name "image.bob" into the listBoxImages that I have on the form.
but i cant seem to get it to work :(
can anyone help me here?
many thanks,
Hypeh