Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.net "cant open file because it is being used by another process."prob

Status
Not open for further replies.

A1METALHEAD

Programmer
May 21, 2004
76
US
hello! i just have a quick question: why would it come up with a
"cant onpen file because it is being used by another process" exeption? i have some code (much to0 big to post here) that makes one filestream (set to 'index.dat'), then one binaryreader from that stream. the reader reads index.dat and looks for a number (the number is how many names is in index.dat) then it loops thru that many times, and each loop grabs a stirng from index.dat and opens 'members\ + the string it grabed + .dat' adn creates another filestream, and another reader off that stream. here is a code snippit from where im getting the error:
Code:
		BinaryWriter* br = new BinaryWriter( fs );
		br->BaseStream->Seek( 0 , SeekOrigin::Begin );

		br->Write( memberInfo->Count );

		for( int i = 0; i < memberInfo->Count; i++ )
		{
			infoParams* temp = dynamic_cast<infoParams*>(memberInfo->Item[i]);
			br->Write( temp->name );

			String* msg = new String("");
			msg = msg->Insert( msg->Length , home );
			msg = msg->Insert( msg->Length , "Members\\" );
			msg = msg->Insert( msg->Length , temp->name );
			msg = msg->Insert( msg->Length , ".dat" );

			FileStream* fs2;
			try
			{
				fs2 = new FileStream( msg , FileMode::OpenOrCreate , FileAccess::ReadWrite );
			}
			catch( DirectoryNotFoundException* e )
			{
				MessageBox::Show( e->ToString() );
				return;
			}
			BinaryWriter* br2 = new BinaryWriter( fs2 );
			br2->BaseStream->Seek( 0 , SeekOrigin::Begin );

			br2->Write( temp->rank );
			br2->Write( temp->nickname );
			br2->Write( temp->task );
			br2->Write( temp->e_mail );

			br2->Write( temp->finished );
			br2->Write( temp->failed );

			if( temp->active )
				br2->Write( S"act" );
			else
				br2->Write( S"ina" );
		}
Thanks!
~metalhead
 
Looks me that u have opened this file in other program. Check it! Did you compile your program? If yes try to run it out of VC.NET
 
ok, i found out what happend... it dosent like having two filestreams at on the same file at a time.. so, i just made an ArrayList() of all the filestreams that i ever opend, and when i need that file, i just take them outta my ArrayList()... thanks anyway!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top