Click here to Skip to main content
15,881,852 members
Home / Discussions / C#
   

C#

 
AnswerRe: MouseUp Event Not Firing After DoDragDrop Pin
Kevin Marois14-Jul-09 7:54
professionalKevin Marois14-Jul-09 7:54 
GeneralRe: MouseUp Event Not Firing After DoDragDrop Pin
Henry Minute14-Jul-09 9:03
Henry Minute14-Jul-09 9:03 
GeneralRe: MouseUp Event Not Firing After DoDragDrop Pin
Kevin Marois14-Jul-09 9:10
professionalKevin Marois14-Jul-09 9:10 
GeneralRe: MouseUp Event Not Firing After DoDragDrop Pin
Henry Minute14-Jul-09 10:10
Henry Minute14-Jul-09 10:10 
GeneralRe: MouseUp Event Not Firing After DoDragDrop [modified] Pin
Kevin Marois14-Jul-09 10:46
professionalKevin Marois14-Jul-09 10:46 
GeneralRe: MouseUp Event Not Firing After DoDragDrop Pin
Henry Minute14-Jul-09 12:06
Henry Minute14-Jul-09 12:06 
GeneralRe: MouseUp Event Not Firing After DoDragDrop Pin
Kevin Marois14-Jul-09 12:38
professionalKevin Marois14-Jul-09 12:38 
QuestionSetting an origin for BinaryReader Pin
SimpleData14-Jul-09 7:16
SimpleData14-Jul-09 7:16 
Hi I have a binary file and I would like to start reading it from an origin. That origin is the location of a string.

I try to find that string with this method:
public long STRLOC(string File, string strToDig)
        {
            FileStream fs = null;
            BinaryReader br = null;

            try { fs = new FileStream(File, FileMode.Open, FileAccess.Read); }
            catch { throw new Exception("Dosya akışı oluşturulamadı."); }

            try { br = new BinaryReader(fs); }
            catch { throw new Exception("Binary okuyucu oluşturulamadı."); }

            try
            {
                byte[] icerik = new byte[fs.Length];
                br.Read(icerik, 0, (int)br.BaseStream.Length);

                string asText = Encoding.UTF8.GetString(icerik);
                int index = asText.IndexOf(strToDig);

                if (index == -1)
                    return -1;

                if (strToDig != asText.Substring(index, strToDig.Length))
                    return -2;

                return index;
            }
            catch { throw new Exception("Dosya okunurken hata oluştu."); }
            finally { br.Close(); fs.Close(); fs.Dispose(); }
        }


I successfully get the location of that string with this method. My string starts at 551828.

Then I want to start reading the file to it's end with this method:

public string ReadBinary(string File, long origin)
{
    FileStream fs = null;
    BinaryReader br = null;

    try { fs = new FileStream(File, FileMode.Open, FileAccess.Read); }
    catch { throw new Exception("Dosya akışı oluşturulamadı."); }

    try { br = new BinaryReader(fs); }
    catch { throw new Exception("Binary okuyucu oluşturulamadı."); }

    try
    {
        br.BaseStream.Position = origin;
        byte[] icerik = new byte[br.BaseStream.Length - origin];

        br.Read(icerik, 0, (int)(br.BaseStream.Length - origin));

        return Encoding.ASCII.GetString(icerik);
    }
    catch { throw new Exception("Dosya okunurken hata oluştu."); }
    finally { br.Close(); fs.Close(); fs.Dispose(); }
}


I call it with ReadBinary("MY FILE'S LOCATION", 551828)

But it doesn't start reading from the position of my string. It just starts from somewhere a lot before my string or beginning.

What am I doing here wrong? Why doesn't my BinaryReader start from the location that I've set with br.BaseStream.Position = origin;, I've tried br.BaseStream.Seek(origin,SeekOrigin.Begin); but it doesn't work too.

Thanks in advance.
QuestionC# struct and NuSOAP(php) Pin
OptiPlex14-Jul-09 6:58
OptiPlex14-Jul-09 6:58 
AnswerRe: C# struct and NuSOAP(php) Pin
dataminers14-Jul-09 9:23
dataminers14-Jul-09 9:23 
GeneralRe: C# struct and NuSOAP(php) Pin
OptiPlex14-Jul-09 9:26
OptiPlex14-Jul-09 9:26 
GeneralRe: C# struct and NuSOAP(php) Pin
dataminers14-Jul-09 9:30
dataminers14-Jul-09 9:30 
GeneralRe: C# struct and NuSOAP(php) Pin
Almighty Bob21-Jul-09 2:11
Almighty Bob21-Jul-09 2:11 
AnswerRe: C# struct and NuSOAP(php) Pin
Almighty Bob21-Jul-09 2:06
Almighty Bob21-Jul-09 2:06 
QuestionImage (Bitmap) Brightness/Contrast Pin
lexx_zone14-Jul-09 6:55
lexx_zone14-Jul-09 6:55 
AnswerRe: Image (Bitmap) Brightness/Contrast Pin
vineas14-Jul-09 7:06
vineas14-Jul-09 7:06 
AnswerRe: Image (Bitmap) Brightness/Contrast Pin
Luc Pattyn14-Jul-09 7:09
sitebuilderLuc Pattyn14-Jul-09 7:09 
AnswerRe: Image (Bitmap) Brightness/Contrast Pin
lexx_zone14-Jul-09 8:38
lexx_zone14-Jul-09 8:38 
QuestionBest method for syntax highlighting Pin
WebMaster14-Jul-09 6:36
WebMaster14-Jul-09 6:36 
AnswerRe: Best method for syntax highlighting Pin
Luc Pattyn14-Jul-09 7:31
sitebuilderLuc Pattyn14-Jul-09 7:31 
GeneralRe: Best method for syntax highlighting [modified] Pin
WebMaster14-Jul-09 8:45
WebMaster14-Jul-09 8:45 
GeneralRe: Best method for syntax highlighting Pin
Luc Pattyn14-Jul-09 15:19
sitebuilderLuc Pattyn14-Jul-09 15:19 
GeneralRe: Best method for syntax highlighting Pin
WebMaster14-Jul-09 20:47
WebMaster14-Jul-09 20:47 
GeneralRe: Best method for syntax highlighting Pin
Luc Pattyn15-Jul-09 0:03
sitebuilderLuc Pattyn15-Jul-09 0:03 
GeneralRe: Best method for syntax highlighting Pin
WebMaster15-Jul-09 1:24
WebMaster15-Jul-09 1:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.