0

Hello ))
Guys tell me please - in which folder should I put the file ( a few folders in one project), so that the program will be able to "read" it. if the path = "something.txt".
Thanks in advance ))

3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by iconoclazt
0
string startupPath1 = System.IO.Directory.GetCurrentDirectory();
//or:
string startupPath2 = Application.StartupPath;

This will return the path of the debug diredctory in the current project.

1

if you want to read the file from the debuf folder in your current project you simply bind the text file, like:

string startupPath2 = Application.StartupPath + @"\something.txt"; //or maybe without backslash! try it(I am doing this code by my heart).
0

I am doing this code by my heart

good phrase)) I'll try ) but why need @ ??

Edited by vedro-compota: n/a

1

If you dont use the sign "@" on the beginning of the path`s string, you have to write double back slashes for seperating folder. Example:

string path1 = @"C:\myFoler\myFile.txt";
string path2 = "C:\\myFolder\\myFile.txt";

I hope you see the difference between these two examples.

Mitja

1

You could always create a directory specifically for your application which would house many important files pertinent to the aforementioned application.

public string storageDirectory;

public void InstallStorageDirectory()
{
    // I've found that LocalApplicationData and ApplicationData seem to be interchangeable.
    this.storageDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\yourStorageDir"

    if (!IO.Directory.Exists(this.storageDirectory))
    {
        try
        {
            Directory.CreateDirectory(path);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }
    else
    {
        Console.WriteLine("..the storage directory is already installed");
    }
}

Edited by iconoclazt: n/a

Votes + Comments
+++++
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.