file access error


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: file access error

  1. #1
    Cam Guest

    file access error


    I am new to the C# world.

    What I am trying to do is create a file and then serialize an object to the
    file.

    It works great if the file exists.

    But if I have to create a fileinfo object and create the file I get the following
    error :

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

    Additional information: The process cannot access the file "c:\temp\xxx"
    because it is being used by another process.

    I can't see a Close property or method for either File class or Fileinfo
    class.

    What am I doing wrong?

  2. #2
    Sergey Kats Guest

    Re: file access error

    How are you opening the file?
    Try this:

    string path = @"c:\yourpath\yourfile.dat";
    FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write,
    FileShare.None);
    serializer.Serialize(fs, yourObj);
    fs.Close();

    Sergey.

    "Cam" <cameron.moore@integic.> wrote in message
    news:3c5ee608$1@10.1.10.29...
    >
    > I am new to the C# world.
    >
    > What I am trying to do is create a file and then serialize an object to

    the
    > file.
    >
    > It works great if the file exists.
    >
    > But if I have to create a fileinfo object and create the file I get the

    following
    > error :
    >
    > An unhandled exception of type 'System.IO.IOException' occurred in

    mscorlib.dll
    >
    > Additional information: The process cannot access the file "c:\temp\xxx"
    > because it is being used by another process.
    >
    > I can't see a Close property or method for either File class or Fileinfo
    > class.
    >
    > What am I doing wrong?




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center