Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:53:43+00:00 2026-06-11T19:53:43+00:00

i am having two problems: 1- when ever i click on open button, it

  • 0

i am having two problems:
1- when ever i click on open button, it shows me the openfiledialog twice (when i select my file and click ok, it reopens the selection windows again, only repeats it once).
2- i am trying to export and import text files from a list view, so far i managed to export a text file from the list view, but i failed at importing it back in.

here is my code (for both situations since it’s the same project):

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    string path;
    //string fname;
    private void abtmenuItem10_Click(object sender, EventArgs e)
    {
        MessageBox.Show("DB Kai UB Text Extractor\n by Omarrrio 2012", "About...", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, 0, "http://gbatemp.net/user/245642-omarrrio/"); 
    }

    private void exitmenuItem4_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void sbtmenuItem5_Click(object sender, EventArgs e)
    {
        listView1.Items.Clear();
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Title = "Open Sbt File";
        ofd.Filter = "Sbt Files (*.sbt)|*.sbt|All Files (*.*)|*.*";
        //if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    }

    private void msgmenuItem6_Click(object sender, EventArgs e)
    {
        listView1.Items.Clear();
        pntrsmenuItem4.Text = "Number of Pointer = ";
        OpenFileDialog ofd = new OpenFileDialog();
        ofd.Title = "Open Msg File";
        ofd.InitialDirectory = Application.StartupPath;
        ofd.Filter = "Msg Files (*.msg)|*.msg|All Files (*.*)|*.*";
        DialogResult result = ofd.ShowDialog();
        if (result == DialogResult.Cancel)
            return;
        if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            path = ofd.FileName;
            BinaryReader br = new BinaryReader(File.OpenRead(path), Encoding.GetEncoding("Shift_JIS"));
            br.BaseStream.Position = 0x4;
            int num_pointers = br.ReadInt16();
            if (num_pointers == 0x56C)
            {
                MessageBox.Show("This File is not supported as it's pointer system is somehow F*cked up, please use another file, thank you.","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return;
            }
            else
            {
            MessageBox.Show("File opened Succesfully!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            pntrsmenuItem4.Visible = true;
            pntrsmenuItem4.Text += num_pointers.ToString();
            List<int> offsets = new List<int>();
            for (int i = 2; i <= (num_pointers * 2); i += 2)
            {
                br.BaseStream.Position = i * 4 + 4;
                offsets.Add(br.ReadInt32());
                //listView1.Items.Add(br.ReadUInt32().ToString("X"));
            }
            Dictionary<int, string> values = new Dictionary<int, string>();
            for (int i = 0; i < offsets.Count; i++)
            {
                int currentOffset = offsets[i];

                int nextOffset = (i + 1) < offsets.Count ? offsets[i + 1] : (int)br.BaseStream.Length;

                int stringLength = (nextOffset - currentOffset - 1) / 2;

                br.BaseStream.Position = currentOffset;

                var chars = br.ReadChars(stringLength);
                values.Add(currentOffset, new String(chars));
            }

            foreach (int offset in offsets)
            {
                listView1.Items.Add(offset.ToString("X")).SubItems.Add(values[offset]);
            }

            br.Close();
            br = null;
            }
        }
        ofd.Dispose();
        ofd = null;
    }

    private void EtxtmenuItem8_Click(object sender, EventArgs e)
    {

        SaveFileDialog sfd = new SaveFileDialog();
        sfd.Title = "Save Text File";
        sfd.DefaultExt = ".txt";
        sfd.InitialDirectory = Application.StartupPath;
        sfd.Filter = "Text Files (*.txt)|*.txt";
        DialogResult result = sfd.ShowDialog();
        if (result == DialogResult.Cancel)
            return;
        StreamWriter wwrite = new StreamWriter(sfd.FileName, false, Encoding.Unicode);
        for (int i = 0; i < listView1.Items.Count; ++i)
        {
            string name = listView1.Items[i].SubItems[1].Text;
            wwrite.WriteLine("-" + name);
        }
        wwrite.Close();
    }

    private void ItxtmenuItem4_Click(object sender, EventArgs e)
    {
        OpenFileDialog ifd = new OpenFileDialog();
        ifd.Title = "Open Text File";
        ifd.Filter = "Text Files (*.txt)|*.txt";
        ifd.InitialDirectory = Application.StartupPath;
        DialogResult result = ifd.ShowDialog();
        if (result == DialogResult.Cancel)
            return;
        StreamReader sr = new StreamReader(ifd.FileName);
        int aa = 0;
        while (sr.Peek() >= 0)
        {
            string[] a2 = sr.ReadLine().Split('-');

            if (a2.Length == 2)
            {
                aa = int.Parse(a2[0].ToString());
                listView1.Items[aa].SubItems[1].Text = a2[1].Replace("~", "\n");
            }
            else
            {
                listView1.Items[aa].SubItems[1].Text += "\n" + a2[0];
            }

        }
        sr.Close();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T19:53:44+00:00Added an answer on June 11, 2026 at 7:53 pm

    It’s a bit hard to see which Menu click corresponds to which method here, but I’ll I’m guessing that the offending piece of code is msgmenuItem6_Click.

    The reason that the Dialog is showing up twice is because you call ShowDialog twice.

    DialogResult result = ofd.ShowDialog();
    if (result == DialogResult.Cancel)
        return;
    if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    

    You should be doing

    if (result == System.Windows.Forms.DialogResult.OK)
    

    Regarding why you aren’t able to read your file. Are you certain that there is data in the while you’re trying to read? To ensure that you are opening it correctly, you can also try File.ReadAllText and make sure that it’s being read in correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having two problems when trying to configure the Struts 2 File Upload Interceptor
I'm having problems multiplying two matrices of dimensions 5000x1024. I tried to do it
I am using MVC-View Model, EF Model first I am having problems with two
Having problems with the combining of two statements in a controller. Both statements work
I was having problems while intersecting two geometries, getting a TopologyException probably due to
We are having problems with understanding the different between the QUORUM and TWO ConsistencyLevel
We are having some problems deploying our WCF services into IIS7. We have two
I'm having some problems trying to perform a query. I have two tables, one
I am having two problems. First: Trying to submit this form using jquery. When
I am having two problems with viewcontrollerss in landscape orientation on the iPad. (1)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.