Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hay there, I have a problem moving mp3 files to directory near the app but I get a DirectoryNotFound Exception here´s the code:
Synchronizer Sync = new Synchronizer();
                foreach(string file in OFD.FileNames)
                {
                    string path = @"";
                    path = OFD.FileName;
                    string name = @"";
                    name = OFD.SafeFileName;
                    Sync.MediaSync(path, name, true);
                }

THIS HAPPENS WHEN YOU TOUCH THE BUTTON

Here is the method MediaSync of Synchronizer class:
string Filepath = @"Music\" + file;
                if (!File.Exists(Filepath))
                {
                    File.Copy(path, Filepath); // I get the exception right here
                }
                else if (File.Exists(Filepath))
                {
                    File.Delete(Filepath);
                    File.Copy(path, Filepath);
                }


Some example code would be great
Thanks
Posted
Updated 2-Jan-12 12:40pm
v3
Comments
RaviRanjanKr 2-Jan-12 18:29pm    
Edited]Always wrap your code in pre tag[/Edited]

1 solution

Using debugger, check that the source file and the destination file paths are correct.

Also you could simplify this by using File.Copy Method (String, String, Boolean)[^] and set the overwrite to true
 
Share this answer
 
Comments
Espen Harlinn 2-Jan-12 19:03pm    
Good advice :)
Wendelius 3-Jan-12 0:24am    
Thanks Espen :)
Sergey Alexandrovich Kryukov 2-Jan-12 22:51pm    
Good advice, a 5.
--SA
Wendelius 3-Jan-12 0:24am    
Thanks SA :)
Member 8437747 3-Jan-12 19:21pm    
Thanks this method works but I still get the exception, the program is installed on a USB so its diffiult to find or locate the path so I only insert @"" in my other to reffer to the path where my program is located the problem is if only put @"" it wont copy the files and if I put @"Mydoc\"
I´ll get the exception

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900