none
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

    Question

  • hi

     i doing my project in visual c++ 2008 express edition... i have an prob in form application to open a excel sheet through a form eventhough i set my all code permission as "FULLTRUST" in .net configration 1.1 in control panel.. i add my code to open a excel sheet and error i get through it..pls check and tel me a solution..

        private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

         openFileDialog1->Filter = "xls files (*.xls)|*.xls|All files (*.*)|*.*";

         openFileDialog1->FilterIndex = 2;

        openFileDialog1->RestoreDirectory = true;  

     if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)

       {

           System::IO::StreamReader ^ sr = gcnew

          System::IO::StreamReader(openFileDialog1->FileName);

          textBox1->Text = openFileDialog1->FileName;

          String^ Path = openFileDialog1->FileName;

    FileStream^ fs = File::Open(Path, FileMode::Open, FileAccess::Read);

        }          

     }       

    Error:

    An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll

    Additional information: The process cannot access the file 'C:\Documents and Settings\kraj1\Desktop\project\cd_bs_display_controller_v2.0_vis.xls' because it is being used by another process.

    Friday, November 04, 2011 12:59 PM

Answers

  • Hi,

     

    According to your code, I suggest you can delete this statementSystem::IO::StreamReader ^ sr = gcnew System::IO::StreamReader(openFileDialog1->FileName);

     

    Since streamreader has occupied your file, this error occurs in your project.

     

    Best Regards,

    Rob

     


    Rob Pan [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Rob Pan Friday, November 11, 2011 9:05 AM
    Monday, November 07, 2011 8:41 AM