[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1107
  • Last Modified:

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

2 Solutions
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).
Gururaj BadamCommented:

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now