Guest Posted February 28, 2009 Share Posted February 28, 2009 I have written a module which takes copies music from one selected location to another.... This works grand on vista but when i tried it on XP i keep getting directoryNotFound exceptions. I know for a fact that the directory does exist so i cant understand what i'm doing wrong Any help? Thanks guys using System; using System.IO; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Navigation; namespace FYP { public partial class UploadMusic : I_NavigationItem { private Main parentForm = null; private String musicDirectory = null; private String applicationPath = null; public UploadMusic(Main parentForm, String country) { this.InitializeComponent(); this.parentForm = parentForm; this.musicDirectory = @"Games\Scrapbook\" + country + @"\Music\"; this.applicationPath = Properties.Settings.Default.applicationPath; } private void browseButton_Click(object sender, RoutedEventArgs e) { Button sendingButton = (Button)sender; int browseButton = int.Parse(sendingButton.Tag.ToString()); System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog(); openDialog.Filter = "MP3 File (*.mp3)|*.mp3"; openDialog.ShowDialog(); switch (browseButton) { case 1: filePath1.Text = openDialog.FileName.ToString(); break; case 2: filePath2.Text = openDialog.FileName.ToString(); break; case 3: filePath3.Text = openDialog.FileName.ToString(); break; case 4: filePath4.Text = openDialog.FileName.ToString(); break; } } private void uploadButton_Click(object sender, RoutedEventArgs e) { TextBox[] filePaths = { this.filePath1, this.filePath2, this.filePath3, this.filePath4 }; // go through each file path searching for images for (int filePathNumber = 0; filePathNumber < filePaths.Length; filePathNumber++) { // check if file path exists on the computer if (File.Exists(filePaths[filePathNumber].Text.ToString()) == true) { if (File.Exists(musicDirectory + Path.GetFileName(filePaths[filePathNumber].Text.ToString())) == false) { File.Copy(filePaths[filePathNumber].Text.ToString(), musicDirectory + Path.GetFileName(filePaths[filePathNumber].Text.ToString())); } } } parentForm.pop(); parentForm.pop(); } public void navigationChanged() { // cleanup or refresh when navigation changed } public void controlClosed() { // action performed once control permanently closed } Link to comment Share on other sites More sharing options...
0 Antaris Veteran Posted February 28, 2009 Veteran Share Posted February 28, 2009 Have you stepped through the code to see what the value of the direct variable is, you need to make sure that it is valid for that XP system. Link to comment Share on other sites More sharing options...
0 night_stalker_z Posted February 28, 2009 Share Posted February 28, 2009 Try running your exe in the same directory as the musicDirectory as it doesnt look like an absolute path. Link to comment Share on other sites More sharing options...
0 GreenMartian Posted February 28, 2009 Share Posted February 28, 2009 As mentioned, debug & inspect the values you're passing to File.Copy(). Or stick them in a textbox, or spit them out to the console. Link to comment Share on other sites More sharing options...
0 Guest Posted February 28, 2009 Share Posted February 28, 2009 Thanks guys... Had to install visual C# on an XP machine to try it out Turns out it was not getting the correct application path on the Windows XP machine. Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); Had to use this instead Path.GetDirectoryName(Application.ExecutablePath); Link to comment Share on other sites More sharing options...
Question
Guest
I have written a module which takes copies music from one selected location to another....
This works grand on vista but when i tried it on XP i keep getting directoryNotFound exceptions.
I know for a fact that the directory does exist so i cant understand what i'm doing wrong
Any help?
Thanks guys
using System; using System.IO; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Navigation; namespace FYP { public partial class UploadMusic : I_NavigationItem { private Main parentForm = null; private String musicDirectory = null; private String applicationPath = null; public UploadMusic(Main parentForm, String country) { this.InitializeComponent(); this.parentForm = parentForm; this.musicDirectory = @"Games\Scrapbook\" + country + @"\Music\"; this.applicationPath = Properties.Settings.Default.applicationPath; } private void browseButton_Click(object sender, RoutedEventArgs e) { Button sendingButton = (Button)sender; int browseButton = int.Parse(sendingButton.Tag.ToString()); System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog(); openDialog.Filter = "MP3 File (*.mp3)|*.mp3"; openDialog.ShowDialog(); switch (browseButton) { case 1: filePath1.Text = openDialog.FileName.ToString(); break; case 2: filePath2.Text = openDialog.FileName.ToString(); break; case 3: filePath3.Text = openDialog.FileName.ToString(); break; case 4: filePath4.Text = openDialog.FileName.ToString(); break; } } private void uploadButton_Click(object sender, RoutedEventArgs e) { TextBox[] filePaths = { this.filePath1, this.filePath2, this.filePath3, this.filePath4 }; // go through each file path searching for images for (int filePathNumber = 0; filePathNumber < filePaths.Length; filePathNumber++) { // check if file path exists on the computer if (File.Exists(filePaths[filePathNumber].Text.ToString()) == true) { if (File.Exists(musicDirectory + Path.GetFileName(filePaths[filePathNumber].Text.ToString())) == false) { File.Copy(filePaths[filePathNumber].Text.ToString(), musicDirectory + Path.GetFileName(filePaths[filePathNumber].Text.ToString())); } } } parentForm.pop(); parentForm.pop(); } public void navigationChanged() { // cleanup or refresh when navigation changed } public void controlClosed() { // action performed once control permanently closed }Link to comment
Share on other sites
4 answers to this question
Recommended Posts