how to open an open dialogbox using c#.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shaam
    New Member
    • Aug 2006
    • 11

    how to open an open dialogbox using c#.net

    hi frnds,

    iam shaam working on c#.net. i want the way how to open an open dialog box so that i can select the file from that by opening that dialog box and select a file and add the path into a text box....

    i will be very helpful to one and all if u help me in solving this problem...
  • dctuck
    New Member
    • Aug 2006
    • 1

    #2
    Hi,

    I use vb.net, but I think the method will be similar:

    You need to add an OpenFileDialog control to your form (from the toolbox), then call the OpenFileDialog1 .ShowDialog method to display it. The filename, including path, which the user has selected will be OpenFileDialog1 .FileName, so you would just set your textbox.Text property to that.

    You should also check that the user hasn't cancelled the dialog - the .ShowDialog method returns True if a file is selected (i.e. user clicked OK or double clicked filename), or False if they cancelled.

    In VB, you would do this as

    Code:
    If OpenFileDialog1.ShowDialog = True Then
        myTextBox.Text = OpenFileDialog1.FileName
    End If
    Hope this helps,

    Daniel

    Originally posted by shaam
    hi frnds,

    iam shaam working on c#.net. i want the way how to open an open dialog box so that i can select the file from that by opening that dialog box and select a file and add the path into a text box....

    i will be very helpful to one and all if u help me in solving this problem...

    Comment

    • dab
      New Member
      • Aug 2006
      • 3

      #3
      I use VB.NET also, but I know a tad C#, so, here goes:



      Code:
              private void Form1_Load(object sender, EventArgs e)
              {
                  openFileDialog1.Filter = "Text Files .txt|*.txt";
                  openFileDialog1.ShowDialog();
      
      
                  if (openFileDialog1.FileName != "");
                  {
                      textBox1.Text = openFileDialog1.FileName;
      
                  }
      
      
      
              }

      Comment

      • shaam
        New Member
        • Aug 2006
        • 11

        #4
        thanks a lot for the solution, but i need to open an open dialog box in an asp application.her e the openfiledialog option is disabled...

        Comment

        • sangitadeori
          New Member
          • Apr 2007
          • 2

          #5
          Originally posted by shaam
          hi frnds,

          iam shaam working on c#.net. i want the way how to open an open dialog box so that i can select the file from that by opening that dialog box and select a file and add the path into a text box....

          i will be very helpful to one and all if u help me in solving this problem...
          Hai
          Shaam

          I am Sangita Deori,working on C#.Net as a GIS developer in DAKC.I have also gone through your problem,the solution to your problem is very simple.M sendin a piece of code for atleast your programe to run.
          You need to take a OpenDialog box ,text box(now for the properties for the text box do text= multiline, scrollbar as both or vartical anything you could take) and a button .

          Now on button click write the following code.Believe me it will run


          private void button1_Click(o bject sender, EventArgs e)
          {
          openFileDialog1 .ShowDialog();
          string s = openFileDialog1 .FileName;
          MessageBox.Show (s);
          StringReader sr = new StringReader(s) ;
          string t1 = sr.ReadToEnd();
          textBox1.Append Text(t1);
          textBox1.Append Text("********* **************" ); /* for seperating b/w paths,you could commecnt it too*/
          sr.Close();
          }

          Comment

          Working...