Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the test.txt file I embed in the prj and then I use FileStream >
I want to put this test.txt file in this path \ Game \ ya \ <the test.txt file it is in,
This path is before the default, it is located on drive C: \ Game \ ya \
but if it is on D: \ Game \ ya \ or E, F, ... or each computer is different

then how could I find the correct path \ Game \ ya \

Is there any way for it to find the path to put the file tes.txt in the path, not using OpenFileDialogs?



C#
private void button2_Click(object sender, EventArgs e)
        {
          
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("wf2.test.txt");

            //
            string fullPath1 = @"\Game\ya\test.txt";
            // 

            FileStream fileStream = new FileStream(fullPath1, FileMode.Create);

            for (int i = 0; i < stream.Length; i++)
                fileStream.WriteByte((byte)stream.ReadByte());
            fileStream.Close();

            MessageBox.Show("Install successfully");


        }


What I have tried:

C#
<pre> //
            string fullPath1 = @"\Game\ya\test.txt";
 // 

It seems that it is only correct on the Windows drive
Posted
Updated 29-Jan-20 22:27pm

1 solution

Basically, don't.
If this is a read only data file (i.e. your app will not alter it) you should store in the same folder as the EXE file, and either access it via just the file name with no path added, or use the Application.StartupPath Property (System.Windows.Forms) | Microsoft Docs[^] to specify the actual path.

If your app changes the file, then it need to be in a "special place" or your app is likely to fail in production. See here: Where should I store my data?[^]
 
Share this answer
 

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