How to move a File to new location


This code sample will help you to move a file to new location even if the new location does not exist


Namespace used for this is Microsoft.VisualBasic.MyServices which will be imported to your
application using:

using Microsoft.VisualBasic.MyServices;

Referrences to be added to your project

You may need to add reference to microsoft.visualbasic.dll to your project.

code and its description

When we try to copy a file using File.Move method it is required that the destination should exist. If it doesn't, then DirectoryNotFoundException is thrown. You can overcome this problem using filesystem object as follows:

FileSystemProxy FileSystem = new Microsoft.VisualBasic.Devices.Computer().FileSystem;
FileSystem.MoveFile(@"C:\myfolder\myFile.txt",@"D:\yourFoldr" );

FileSystem = null;

In the above example we try to move myFile.txt to a new folder (not yet created) in d:\


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: