OpenFileDialog control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lina

    #1

    OpenFileDialog control

    Hello,

    I wanted to ask if anyone can help me complete the
    following code. I found this example while searching
    through help documnets. What i want to achieve is to open
    a dialog box that lets the user select an images file.
    I am using the openFileDialog control.

    Here is what i have done so far for the onlick event for
    the button...
    Dim myStream As Stream
    Dim openFileDialog1 As New OpenFileDialog( )

    openFileDialog1 .InitialDirecto ry = "c:\"
    openFileDialog1 .Filter = "txt files (*.txt)|*.txt|A ll
    files (*.*)|*.*"
    openFileDialog1 .FilterIndex = 2
    openFileDialog1 .RestoreDirecto ry = True

    If openFileDialog1 .ShowDialog() = DialogResult.OK Then
    myStream = openFileDialog1 .OpenFile()
    If Not (myStream Is Nothing) Then
    ' Insert code to read the stream here.
    myStream.Close( )
    End If
    End If

    Im not sure on what to write for the stream code (where
    the comment is). Does anyone have any useful articles or
    advise.

    thx.
  • Shad Murthy

    #2
    OpenFileDialog control

    Here is some C# code sample:

    OpenFileDialog authFileDlg = new OpenFileDialog( );
    authFileDlg.Ini tialDirectory = ".";
    authFileDlg.Fil ter = "auth files (*.fox)|*.fox|A ll files
    (*.*)|*.*";
    authFileDlg.Fil terIndex = 1;
    authFileDlg.Res toreDirectory = true;
    try
    {
    if (authFileDlg.Sh owDialog() == DialogResult.OK )
    {
    Stream myStream = null;
    m_arAuth.Clear( ); //clear the list
    if ((myStream = authFileDlg.Ope nFile()) != null)
    {
    //get the login details
    BinaryFormatter myBinFormat = new BinaryFormatter ();
    m_arAuth = (ArrayList)myBi nFormat.Deseria lize(myStream);
    myStream.Close( );
    }
    }
    }
    catch (Exception ex)
    {
    MessageBox.Show (ex.Message, "!!! OPEN - ERROR !!!");
    return;
    }

    [color=blue]
    >-----Original Message-----
    >Hello,
    >
    >I wanted to ask if anyone can help me complete the
    >following code. I found this example while searching
    >through help documnets. What i want to achieve is to[/color]
    open[color=blue]
    >a dialog box that lets the user select an images file.
    >I am using the openFileDialog control.
    >
    >Here is what i have done so far for the onlick event for
    >the button...
    >Dim myStream As Stream
    > Dim openFileDialog1 As New OpenFileDialog( )
    >
    > openFileDialog1 .InitialDirecto ry = "c:\"
    > openFileDialog1 .Filter = "txt files (*.txt)|*.txt|A ll
    > files (*.*)|*.*"
    > openFileDialog1 .FilterIndex = 2
    > openFileDialog1 .RestoreDirecto ry = True
    >
    > If openFileDialog1 .ShowDialog() = DialogResult.OK[/color]
    Then[color=blue]
    > myStream = openFileDialog1 .OpenFile()
    > If Not (myStream Is Nothing) Then
    > ' Insert code to read the stream here.
    > myStream.Close( )
    > End If
    > End If
    >
    >Im not sure on what to write for the stream code (where
    >the comment is). Does anyone have any useful articles or
    >advise.
    >
    >thx.
    >.
    >[/color]

    Comment

    • Cor

      #3
      Re: OpenFileDialog control

      Hi Lina,

      I do not understand your question, (I understand it but why a stream) if you
      want an image, the only reason can be in my opinion if you want to write it
      to a database direct withouth showing it or something.

      If you only want the image and you do not have used a picture box then it is
      \\\
      dim myimage as image
      If openFileDialog1 .ShowDialog() = DialogResult.OK Then
      myimage.fromfil e(openFileDialo g1.filename)
      End If
      ///

      I hope this helps,

      Cor


      Comment

      • Lina

        #4
        Re: OpenFileDialog control

        Hi Cor,

        I want to load the image into a picture box.
        I wasnt to sure what i was doin and i found this example
        with the stream in it!! :o)

        What do i write if i want to insert the image that is
        selceted by the user into my picturebox?
        Of course i will have to make sure that the user actully
        selects a file!

        Also, I have managed to set the filter to bitmaps, jpegs,
        and all files. However i only want the all files to show
        all the image files. How would i write this??

        Thx for for help#
        :)

        [color=blue]
        >-----Original Message-----
        >Hi Lina,
        >
        >I do not understand your question, (I understand it but[/color]
        why a stream) if you[color=blue]
        >want an image, the only reason can be in my opinion if[/color]
        you want to write it[color=blue]
        >to a database direct withouth showing it or something.
        >
        >If you only want the image and you do not have used a[/color]
        picture box then it is[color=blue]
        >\\\
        >dim myimage as image
        > If openFileDialog1 .ShowDialog() = DialogResult.OK Then
        > myimage.fromfil e(openFileDialo g1.filename)
        >End If
        >///
        >
        >I hope this helps,
        >
        >Cor
        >
        >
        >.
        >[/color]

        Comment

        • Cor

          #5
          Re: OpenFileDialog control

          Hi Lina,

          fdlOpen.Filter = "All Image Formats (*.bmp;*.jpg;*. jpeg;*.gif;*.ti f)|" & _
          "*.bmp;*.jpg;*. jpeg;*.gif;*.ti f|Bitmaps (*.bmp)|*.bmp|" &
          _
          "GIFs (*.gif)|*.gif|J PEGs (*.jpg)|*.jpg;* .jpeg|TIFs
          (*.tif)|*.tif"

          And than of course simple.

          Picturebox1.ima ge.fromfile(ope nFileDialog1.fi lename)

          I hope this was what you where looking for?

          Cor


          Comment

          • Mike

            #6
            Re: OpenFileDialog control

            There is a good example on

            Hours of .Net and Sql Server videos for $20

            Comment

            • Lina

              #7
              Re: OpenFileDialog control

              Hi Cor,

              I have used the following code but the image doesnt seem
              to load into my picture box!!

              OpenFileDialog1 .InitialDirecto ry = "c:\"
              OpenFileDialog1 .Filter = "All Image Formats
              (*.bmp;*.jpg;*. jpeg;*.gif;*.ti f)|" & _
              "*.bmp;*.jpg;*. jpeg;*.gif;*.ti f|Bitmaps (*.bmp)|*.bmp|"
              & _
              "GIFs (*.gif)|*.gif|J PEGs (*.jpg)|*.jpg;* .jpeg|TIFs
              (*.tif)|*.tif"

              OpenFileDialog1 .FilterIndex = 2
              openFileDialog1 .RestoreDirecto ry = True

              If openFileDialog1 .ShowDialog() = DialogResult.OK Then
              PictureBox1.Ima ge.FromFile(Ope nFileDialog1.Fi leName)
              End If

              [color=blue]
              >-----Original Message-----
              >Hi Lina,
              >
              > fdlOpen.Filter = "All Image Formats[/color]
              (*.bmp;*.jpg;*. jpeg;*.gif;*.ti f)|" & _[color=blue]
              > "*.bmp;*.jpg;*. jpeg;*.gif;*.ti f|Bitmaps[/color]
              (*.bmp)|*.bmp|" &[color=blue]
              >_
              > "GIFs (*.gif)|*.gif|J PEGs (*.jpg)[/color]
              |*.jpg;*.jpeg|T IFs[color=blue]
              >(*.tif)|*.ti f"
              >
              >And than of course simple.
              >
              >Picturebox1.im age.fromfile(op enFileDialog1.f ilename)
              >
              >I hope this was what you where looking for?
              >
              >Cor
              >
              >
              >.
              >[/color]

              Comment

              • Cor

                #8
                Re: OpenFileDialog control

                Hi Lina,

                Sorry it was to quick and dirty typed

                [color=blue]
                > PictureBox1.Ima ge.FromFile(Ope nFileDialog1.Fi leName)[/color]

                PictureBox1.Ima ge = image.FromFile( OpenFileDialog1 .FileName)

                I think it will go now?

                Cor


                Comment

                • Lina

                  #9
                  Re: OpenFileDialog control

                  thx Cor,

                  it is working now :o)
                  Your help is appreciated.
                  [color=blue]
                  >-----Original Message-----
                  >Hi Lina,
                  >
                  >Sorry it was to quick and dirty typed
                  >
                  >[color=green]
                  >> PictureBox1.Ima ge.FromFile(Ope nFileDialog1.Fi leName)[/color]
                  >
                  >PictureBox1.Im age = image.FromFile[/color]
                  (OpenFileDialog 1.FileName)[color=blue]
                  >
                  >I think it will go now?
                  >
                  >Cor
                  >
                  >
                  >.
                  >[/color]

                  Comment

                  Working...