I have a program made, but my coding skills are quite poor thus i am here to seek some help.
Ok this is what i have:
a program that reads in a list of files, then stores displays them into a list box, using a recursive search. when it searches all the files, it reads the data of the file and then stores it into a string.
at the moment, i have it hard coded, so it then checks an already stored set of data and checks if the data in the file it checks contains the data.
e.g. file.txt is read in, and "in football there teams have 11 men on them". it then does a check. i have already stored entries such as "teams have 11 men". the program checks if the file contains "teams have 11 men". because it does. it moves it to a listbox called "sports".
heres a little example of a small version of the xml file:
11 man team
40 love
hit a 6
take £200
counter terrorists
collect caps
as you can see from the above xml. i have "sports" "games". i intend to add a lot more. in each one, in sports for example it has "football", "tennis" and so on.
obviously, my program is a recursive search, so i want it to run check 1 file after the other. if that makes sense?
i think i need it like:
for each file:
Read XML File
check if the string contains any of the data in the xml file (so it checks down the list till it finds a match)
if it matches (e.g. football matches the content of the string) then display football file name in a listbox for sports
if it matches (e.g. 40 love matches the content of the string) then it displays the file name in a list box for sports... because in the xml above, it shows its tennis, which is in the sports list. and so on.
does this make sense?
how can i go about doing this?
many thanks in advance.
Hypeh
Hypeh VipehPosted Mar 12, 2011, 4:51 PM
I got it part working..
i have replaced the stored stuff with the XML stuff but running into some problems.
could you maybe explain why the 2 Strings i have declaired dont work?
XMLHex
and
XMLExtension
they both get blue lines beneath them.. :(
it says does not exist in current context
XDocument myDoc = XDocument.Load("FileSigs.xml");
IEnumerable
from Images in FileSigs.Elements()
from sigs in Images.Elements()
where (storedFileSig.Contains(sigs.Value))
select sigs.Attribute("name").Value;
IEnumerable
from Images in FileSigs.Elements()
from sigs in Images.Elements()
where (storedFileSig.Contains(sigs.Value))
select sigs.Value;
foreach (String r in ImagesResult1)
{
strFileType = "Image";
string XMLExtension = r;
}
foreach (String r in ImagesResult2)
{
string XMLHex = r;
}
if (hex.Contains(XMLHex) && (!inFile.Contains(XMLExtension))) //use sub string
{
strFileType = "Suspect";
}
else if (hex == XMLHex)
{
strFileType = "Image";
}
else if (hex != XMLHex)
{
strFileType = "Not Valid JPG File";
}
return strFileType;
}
Suthish NairPosted Mar 12, 2011, 3:55 PM
Both the outputs are different..
textBoxXMLExtension
textBoxStored
var xmlAtt = from att in myDoc.Elements("Filesigs").Elements("Images")
Hypeh VipehPosted Mar 12, 2011, 3:54 PM
i fixed 1 part:
first file sig in XML should be FF D8 FF E0
i fixed that and it now works with the string.
my next question is.
how can i tell it to display the sig from th XML in a txt box?
many thanks
Hypeh
Hypeh VipehPosted Mar 12, 2011, 3:10 PM
the image is called "koala.bob" sorry not image.bob.
here it is:
http://www.fileserve.com/file/hUmkhEz
Suthish NairPosted Mar 12, 2011, 3:06 PM
Hypeh VipehPosted Mar 12, 2011, 2:52 PM
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:
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
Sam HobbsPosted Mar 12, 2011, 2:49 PM
I doubt that I will have time to look at your code. It is likely no one will. You are more likely to get help if you explain what you need to do and what you are having problems with.
Another thing that can make a huge difference is if you can modularize your project in the sense of asking about specific tasks instead of asking about the entire whole project.
Note that the part of the original question that says "reads in a list of files" .... "into a list box, using a recursive search" is confusing. I don't understand how recursion is relevant there.
I think that the hardest part of getting answers is being able to describe the problem. Showing us code that does not satisfy the requirements does not help us understand what it is supposed to do. If however you can explain the requirements adequately enough for others to understand, then there is a good chance that you will understand the requirements well enough for you to do it.
Hypeh VipehPosted Mar 12, 2011, 1:15 PM
let me explain with my Real program im trying to use it for.
I have some code partly working but its not working completely.
Ok, my program is intended to take a file. read its first 20 bytes and then convert to HEX and store in a string.
it then looks at the XML file, and checks which file signature it contains.
so a file called "image.bob" may be chosen. but it is really "image.jpg" but someone has renamed it.
i have an XML with file sig values stored.
i have the program reading the first 20 bytes.
but im running into a few problems.
Shall I upload my project and give you a link so you can see?
Regards,
Hypeh
Suthish NairPosted Mar 12, 2011, 1:01 PM
Hypeh VipehPosted Mar 11, 2011, 9:04 AM
Hypeh VipehPosted Mar 10, 2011, 5:12 PM
Thank you for your reply.
I have looked at example codes for XML reading etc, but if i am 100% honest, they just seem very complicated... this sounds rather stupid, but i struggle with like stringing things together. so when i see the examples and it refers to stuff like that example "country.xml" i get really confused?
Would you happen to be kind enough to possibly provide a small snippet? or example code to what i have put in my first post? Its only a tiny tiny tiny bit of what im intending to do, but im just hoping if i have some sort of starting point like i have shown in my first post. I can then progress from it?
I would be forever in ur debt! :) if anyone can help me
thank you!
Hypeh
Suthish NairPosted Mar 10, 2011, 2:40 PM