Hi all .. i have given this code in my project.. it is showing

Access to the path 'C:\Documents and Settings' is denied.

I dont know what is wrong.. this code works if i give the path different...

can any help me...

Thnaks

vince

private void FileView()
        {
            TreeNode RootNode = new TreeNode("Root");
            treeView2.Nodes.Add(RootNode);
            PopulateTreeView(@"C:\", RootNode);
        }

        public void PopulateTreeView(string directory, TreeNode Node)
        {

            string[] Directories = Directory.GetDirectories(directory);
            string[] Files = Directory.GetFiles(directory);

            foreach (string folder in Directories)
            {
                TreeNode FolderNode = new TreeNode(Path.GetFileName(folder));
                Node.Nodes.Add(FolderNode);
                this.PopulateTreeView(folder, FolderNode);
            }

            foreach (string file in Files)
            {
                TreeNode FileNode = new TreeNode(Path.GetFileName(file));
                Node.Nodes.Add(FileNode);
            }
        }

If the file you want to access is always going to be in the same directory locate the file, copy the complete directory and put the file name and extention on the end of the directory like:

@"C:\\temp\\XmlFiles\\MyFile.xml"

I am creating files and access this files from documents folder..... I have no others place to create file for client.... and store the output files in this folders........

have any other idea...

Thanks for ur reply
vince

i am creating many folder inside this... and most of the file types are text....

This not a right way when you will deploy you project how will you do then??? make a folder in C: of any other drive like C:\folderProject and then add other folders or files inside it don't use document and settings coz that is

Try using a saveFileDialog control and return the selected path. if you use the saveFileDialog control you can create the folders before hand, navigate to the folder you want to save your text file to, enter the desired name for the file and then use the .FileName property of the saveFileDialog control to get the path. You can use an openFileDialog control to do the opposite and it allows you to select any type of file.

As for creating a text file i've no idea as i've only created Xml files sorry.

This article has been dead for over six months. Start a new discussion instead.