CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2008
    Posts
    70

    Open File Dialog

    Hello i am making a simple program in visual c++, i have it so that when i hit a button the Open File dialog pops up. But when i open something i want it to return the file name of what i opened so that my program my deal with it.

    Here is my attempt

    Code:
    string account2;
    account2 = openFileDialog1->FileName;
    The error i receive.

    binary '=' : no operator found which takes a right-hand operand of type 'System::String ^' (or there is no acceptable conversion)


    Can someone please step me in the right direction? Many Thanks - marsh

  2. #2
    Join Date
    Apr 2008
    Posts
    9

    Re: Open File Dialog

    This works quite fine, try it
    String^ account2;
    account2=openFileDialog1->FileName;
    THANX

  3. #3
    Join Date
    Apr 2009
    Posts
    598

    Re: Open File Dialog

    It seems your example is for Visual basic of C++.
    Visual C++
    private:
    void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
    {
    Stream^ myStream;
    OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;

    openFileDialog1->InitialDirectory = "c:\\";
    openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
    openFileDialog1->FilterIndex = 2;
    openFileDialog1->RestoreDirectory = true;

    if ( openFileDialog1->ShowDialog() == System::Windows::Forms:ialogResult::OK )
    {
    if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
    {
    // Insert code to read the stream here.
    myStream->Close();
    }
    }
    }

    (Source: http://msdn.microsoft.com/en-us/libr...iledialog.aspx)

  4. #4
    Join Date
    Sep 2008
    Posts
    70

    Re: Open File Dialog

    Thank you i got it working.

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Open File Dialog

    [ moved thread ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured