Click here to Skip to main content
15,867,954 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make a media player with wmp in a winform. I am also using a treeview to browse the files.
this is the code that I am using:

private void ListDirectory()
        {
            list.Nodes.Clear();
            var rootDirectoryInfo = new DirectoryInfo(Path.GetFullPath(Application.StartupPath));
            path.Text = rootDirectoryInfo.ToString();
            list.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo));
        }

        private static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo)
        {
            var directoryNode = new TreeNode(directoryInfo.Name);
            foreach (var directory in directoryInfo.GetDirectories())
                directoryNode.Nodes.Add(CreateDirectoryNode(directory));
            foreach (var file in directoryInfo.GetFiles())
                directoryNode.Nodes.Add(new TreeNode(file.Name));
            return directoryNode;
        }
private void list_AfterSelect(object sender, TreeViewEventArgs e)
        {
            WMPLib.IWMPPlaylist playlist = player.playlistCollection.newPlaylist("media_playlist");
            WMPLib.IWMPMedia media;            
            DirectoryInfo dir = new DirectoryInfo(Path.GetFullPath(Path.GetFileName(list.SelectedNode.Text)));
            if (list.SelectedNode.FullPath.Length!=0)
            {
            foreach (var file in dir.GetFiles())
            {                
                media = player.newMedia(Path.GetFullPath(Path.GetFileName(file.ToString())));
                playlist.appendItem(media);                
                path.Text=Path.GetFullPath(Path.GetFileName(file.ToString()));               
            }
            list.Visible = false;
            player.currentPlaylist = playlist;
            player.Ctlcontrols.play();            
            private void list_AfterSelect(object sender, TreeViewEventArgs e)
        {
            WMPLib.IWMPPlaylist playlist = player.playlistCollection.newPlaylist("media_playlist");
            WMPLib.IWMPMedia media;

//I am getting the error with this variable in the foreach statement below            
            DirectoryInfo dir = new DirectoryInfo(Path.GetFullPath(Path.GetFileName(list.SelectedNode.Text)));
            
            foreach (var file in dir.GetFiles())
            {                
                media = player.newMedia(Path.GetFullPath(Path.GetFileName(file.ToString())));
                playlist.appendItem(media);                
                path.Text=Path.GetFullPath(Path.GetFileName(file.ToString()));               
            }
            list.Visible = false;
            player.currentPlaylist = playlist;
            player.Ctlcontrols.play();            
            
        }
        }


This works fine when I have the files in the same directory as the app, but when I place files inside folders inside the app's folder, I get the could not find part of path error.
Can someone please help me fix this problem?
Thanks in advance!
Posted
Updated 21-Sep-15 10:26am
v2
Comments
Maciej Los 21-Sep-15 16:22pm    
Fix what?
What's the difference to your previous question?
Member 10850253 21-Sep-15 16:31pm    
Instead of using Directory.GetCurrentDirectory(), I used Application.startuppath
Herman<T>.Instance 21-Sep-15 16:23pm    
What's in the selectedNode?
Member 10850253 21-Sep-15 16:27pm    
A video file
Herman<T>.Instance 21-Sep-15 16:29pm    
the file or the path and name to it?

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