John

John

  • NA
  • 43
  • 34k

path has $$$$ instead of \\

Jul 21 2013 12:47 PM
Hi guys,

I have 2 forms which do practical the same thing. They are supposed to show a preview of a file which has been selected from a treeview. However the first form works fine and the second one doesn't. When I look into it the second form produces a path with "$$$$" instead of "\\ ". Ive been over the code a few times trying to figure out what the difference is but with no luck.


Heres Form 1

//open tree
        private void button2_Click(object sender, EventArgs e)
        {
            ListDirectory(treeView1,@"C#");
            treeView1.ExpandAll();
            //empty();
           
           
        }

public 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("*.PDF"))
                directoryNode.Nodes.Add(new TreeNode(file.Name));

            if (directoryNode.Nodes.Count == 0)
            {
                treeView1.Nodes.Remove(directoryNode);
               
                //directoryNode.Nodes.Add("No Books");
            }
           


                return directoryNode;
           
        }

private void ListDirectory(TreeView treeView, string path)
        {
            treeView.Nodes.Clear();
            var rootDirectoryInfo = new DirectoryInfo(path);
            treeView.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo));
        }


//Preview
        private void button5_Click(object sender, EventArgs e)
        {
            FileInfo prev = new FileInfo (treeView1.SelectedNode.FullPath);
            //string prev = treeView1.SelectedNode.FullPath;
            switch (prev.Extension.ToUpperInvariant())
            {
                case ".MOV":
                case ".WMV":
                case ".WMP":
                case ".AVI":
                case ".FLV":
                case ".DVI":
                    axWindowsMediaPlayer1.URL = prev.FullName;
                    break;
                case ".PDF":
                case ".CHM":
                case ".DOC":
                    axAcroPDF1.LoadFile(prev.FullName);
                    break;
                case null:
                    MessageBox.Show("theres something wrong");
                    break;
            }

        }


Now heres the next form:

private void button2_Click(object sender, EventArgs e)
        {
           
            ListDirectory(treeView1,@"C#");
            treeView1.ExpandAll();
        }

private void ListDirectory(TreeView treeView, string path)
        {

            treeView.Nodes.Clear();
            var rootDirectoryInfo = new DirectoryInfo(path);
            treeView.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo));
        }

public 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("*.PDF"))
                directoryNode.Nodes.Add(new TreeNode(file.Name));

            if (directoryNode.Nodes.Count == 0)
            {
                treeView1.Nodes.Remove(directoryNode);

                //directoryNode.Nodes.Add("No Books");
            }



            return directoryNode;
        }

//Preview
        private void button12_Click(object sender, EventArgs e)
        {
            FileInfo prev = new FileInfo(treeView1.SelectedNode.FullPath);
            //string prev = treeView1.SelectedNode.FullPath;
            switch (prev.Extension.ToUpperInvariant())
            {
                case ".MOV":
                case ".WMV":
                case ".WMP":
                case ".AVI":
                case ".FLV":
                case ".DVI":
                    axWindowsMediaPlayer1.URL = prev.FullName;
                    break;
                case ".PDF":
                case ".CHM":
                case ".DOC":
                    axAcroPDF1.LoadFile(prev.FullName);
                    break;
                case null:
                    MessageBox.Show("theres something wrong");
                    break;
            }

      
        }


Cheers