How to get file path?

user9889331

I'm working on cook book Windows project, and I prepared some .rtf files to load it in RichTextBox. The problem is that the path of the file can't work at any computer, just mine. The code I used:

richTextBox1.LoadFile("C:\\Users\\nardeen\\Desktop\\cookproject\\cookingproject\\italian.rtf", RichTextBoxStreamType.RichText);

In addition I tried with this but it didn't work:

string FilePath = System.Windows.Forms.Application.StartupPath + "\\italian.rtf";

richTextBox1.LoadFile(FilePath, RichTextBoxStreamType.RichText);
Dour High Arch

Do not use StartupPath or CurrentDirectory for user data; that will change depending on how your application was installed, Standard users won't be able to write to it, and it will probably get deleted if the user repairs their application.

If you are trying to get the path to a folder that the user can read and write to, and that doesn't get deleted when you uninstall or repair the application, use

string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
    "cooking project", "Italian.rtf");

If you want to include some starter data for users, include it in your project as a resource or embedded file, and copy it to the user folder when you install your application. If you tell us what installer technology you use, we can give advice on that as well.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to get full path of a file?

From Java

How to get the path of a running JAR file?

From Java

How to get an absolute file path in Python

From Dev

How to split a file path to get the file name?

From Dev

How to get path in spring to access configuration file

From Dev

ContentResolver -- how to get file path of attachment

From Dev

how to get file path of asset folder in android

From Dev

How To Get Real Path Of A File Using Jquery

From Dev

How to get file path from OpenFileDialog and FolderBrowserDialog?

From Dev

Inno Setup (How to get dynamically path to file)?

From Dev

How to get accurate path of the uploaded file in jsp?

From Dev

How to get file path to show on Netbeans tab

From Dev

How to get the right file path in Servlet program?

From Dev

Laravel - how to get path name of file

From Dev

How to get the file path location of a .jar dependency?

From Dev

How to get .ipa file path

From Dev

JimFS: how to get File from Path

From Dev

How to get the file absolute path in JAVA project

From Dev

How to get path of file with batch

From Dev

How to get file path without extension in Rust?

From Dev

How to get file path from JavaFX FileChooser?

From Dev

How to get original file path of image from

From Dev

How to get audio path to play audio file?

From Dev

How to get asset file path in Xamarin?

From Dev

how to drag a file and get path of it

From Dev

How to get the file path of a buffer?

From Dev

How to get file path dynamically?

From Dev

How to get path of file with batch

From Dev

How to get path of a file in windows