About System.IO.File.Move

Hi Experts,

.Net framework 1.1

I'm in trouble about the System.IO.File.Move method. I'm using it to move a file from a temporary directory to another location. However, after moving the file, I cannot use System.IO.File.Delete to delete the file. The file is being reserved by someone/a program. I tried to remove the file manually on the server but also can't. However, after restarting the WWW service, I can remove the file successfully.... I totally don't know what's the problem, could anyone plese give me a hand?

Code is attached, Thanks a million!!!!
public void moveFile(string Source, string Destination, string FileName)
			if (System.IO.File.Exists(Source + FileName))
				System.IO.File.Move(Source + FileName, Destination + FileName);
				if (System.IO.File.Exists(Destination + FileName))
					System.IO.Stream objFS;
					objFS = System.IO.File.OpenRead(Destination + FileName);
		public void deleteFile(string Path, string FileName)
			if (System.IO.File.Exists(Path + FileName))
				System.IO.File.Delete(Path + FileName);

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

what if you added this before closing

objFS .EndRead();
Maybe explicitly dispose the stream, although the close is supposed to release everything anyway.   Otherwise you might progressively comment out the Exists / Move / Exists / Openread calls to see which one causes it (making sure that there isn't something else going on).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gururaj BadamCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.