How do I find the file path to write my file to?

125 pts.
Tags:
%HOMEPATH% variable
Relative references
System.IO.StreamWriter
Visual Basic
Visual Basic 2008
Here is my code and then my question. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim objfile As New System.IO.StreamWriter("C:Documents and SettingsJOHNDOEMy DocumentsTHETARGETFOLDERMYFILE.TXT") objfile.WriteLine("just a test") objfile.Close() end sub This code will write to my target folder, however if i build my project and make it available for other people to use on their computer I run into the problem of not knowing what the john doe name is. How would i know what they have named their computer. Is there a way around this. any suggestions? -vb 2008
ASKED: December 12, 2008  11:51 PM
UPDATED: December 15, 2008  7:26 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

There’s a couple ways to get around this problem:

1. You can use windows system variables instead of hard-coding the path into your app. For example: Save my file to “%HOMEPATH%\My Documents\MyFile.txt”

2. Prompt the user where they want to save the file and save that in a configuration/ini file in your app’s folder.

3. Save the file to your app’s folder by using the .Net variable Application.StartupPath, which refers to your application’s folder.

- Max

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following