file doesnt show up in the "MyDocuments" folder

spicyadmin

Member
Joined
Dec 23, 2021
Messages
15
Programming Experience
Beginner
Though (sorry to bother again) I am having one other problem now with a different part. I want to read and write to a file in the "MyDocuments" folder. I used the same method as the first problem I was having but the file doesnt show up in the "MyDocuments" folder, the file shows up in the executables directory.

C#:
        private void btn_deletePrevious_Click(object sender, EventArgs e)
        {
            string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            using (StreamWriter writer = new StreamWriter(Path.Combine(docPath, "camList.ini"))) { }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string cDirs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            string line;
            StreamReader file = new System.IO.StreamReader(Path.Combine(cDirs, "camList.ini"));
            while ((line = file.ReadLine()) != null)
            {
                lbx_camList.Items.Add(line); 
            }
            file.Close();
        }
 
The result of Path.Combine here obviously is a path in Documents folder, so it is impossible that code is to blame for producing a file elsewhere.
 
The code in lines 10-18 do only read operations. Why are you expecting it to create a file?

The code in 3-5 would create a file in the My Documents folder, but it would be an empty file.
 
Look at other bits of your code where you may be creating the file named "camList.ini". You may not be putting a path prefix on the filename and thereby creating the file in the same directory as your executable. Ctrl-Shift-F "camList.ini" may aid in the search.
 
Look at other bits of your code where you may be creating the file named "camList.ini". You may not be putting a path prefix on the filename and thereby creating the file in the same directory as your executable. Ctrl-Shift-F "camList.ini" may aid in the search.
it's literally only these two instances. I don't have it placed anywhere else
 
Is "camList.ini" in your solution explorer? If so, what is the build action associated with it? What is the setting of "Copy to Output Dir" for it?

If it is not in your solution explorer, unload the .CSProj file, open it, and search for "camList.ini". Is it present in the .CSPROJ? If so copy and paste into code tags here what the item entry XML for it.

As @JohnH said, some other action is creating that file in your executable directory. It's not those of lines of code you presented in post #1.
 
Last edited:
Is "camList.ini" in your solution explorer? If so, what is the build action associated with it? What is the setting of "Copy to Output Dir" for it?

If it is not in your solution explorer, unload the .CSProj file, open it, and search for "camList.ini". Is it present in the .CSPROJ? If so copy and paste into code tags here what the item entry XML for it.

As @JohnH said, some other action is creating that file in your executable directory. It's not those of lines of code you presented in post #1.
I fixed it. I was hiding a different StreamWriter class in a different project file. Thanks for the help!
 
Back
Top Bottom