8 Replies - 3101 Views - Last Post: 26 August 2008 - 09:06 PM Rate Topic: -----

#1 fenrisulfr  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 16-August 08

Install Directory

Posted 26 August 2008 - 05:30 PM

How can I have stream writer open a file in the install directory if the install directory's are different on every computer?

is there any way besides scanning the entire HDD for the .exe file and setting the .exes directory as the default one?

This post has been edited by fenrisulfr: 26 August 2008 - 05:34 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Install Directory

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Install Directory

Posted 26 August 2008 - 05:50 PM

If you do not provide a path to the file, then it will only look in the directory that contains the EXE file. Without a path supplied, it will look in the directory relative to where the EXE is.

The following example will look in the directory containing the EXE:
Dim reader As New StreamReader("file.txt")



As opposed to this which will look only on the C drive:
Dim reader As New StreamReader("C:\file.txt")



The first example is how you want to do it.
Was This Post Helpful? 0
  • +
  • -

#3 fenrisulfr  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 16-August 08

Re: Install Directory

Posted 26 August 2008 - 07:17 PM

but if i had it in a subdirectory of the .exe would it be
Dim reader As New StreamReader("\saved\file.txt")

??
Was This Post Helpful? 0
  • +
  • -

#4 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Install Directory

Posted 26 August 2008 - 07:26 PM

If it is stored inside a folder in the same directory as the EXE then you need to get the StartUpPath using the Application class. The StartupPath will provide you with the absolute path to where the EXE is stored.

Like so:
Dim reader As New StreamReader(Application.StartupPath & "\saved\file.txt")

Was This Post Helpful? 0
  • +
  • -

#5 fenrisulfr  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 16-August 08

Re: Install Directory

Posted 26 August 2008 - 07:29 PM

so i can use that code for the final project but what should i use for when its in development?

like im still coding it?
Was This Post Helpful? 0
  • +
  • -

#6 indrora  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 100
  • Joined: 25-July 08

Re: Install Directory

Posted 26 August 2008 - 08:17 PM

Application.StartupPath is a variable that allows you to get the directory of where the application is running from -- Unlike the Current Working Directory, which is changed at semi-random (ie your user opens a file with the Open File Dialog box). This doesnt change but its the initial path.

Use Application.Info.DirectoryPath for the location of the assembly :3

Edit: Always in your code assume you're in a production environment unless there is a SPECIFIC reason not to.

This post has been edited by indrora: 26 August 2008 - 08:18 PM

Was This Post Helpful? 0
  • +
  • -

#7 fenrisulfr  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 16-August 08

Re: Install Directory

Posted 26 August 2008 - 08:50 PM

Does this only make a temporary file when the code is run inside of VB.net?
Was This Post Helpful? 0
  • +
  • -

#8 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Install Directory

Posted 26 August 2008 - 09:04 PM

View Postfenrisulfr, on 26 Aug, 2008 - 07:29 PM, said:

so i can use that code for the final project but what should i use for when its in development?

like im still coding it?

It will be the same for development as when testing. It always gets the current location of the EXE, regardless of where it is stored on the hard drive, with one exception.

If you use ClickOnce for deployment of your application then you need to use the following. In addition, you must deploy the application with Full Trust in order for it to work. See the following links for more information.
Dim reader As New StreamReader(ApplicationDeployment.CurrentDeployment.DataDirectory & "\saved\file.txt")


Accessing Local and Remote Data in ClickOnce Applications
ClickOnce Deployment and Security
Was This Post Helpful? 0
  • +
  • -

#9 fenrisulfr  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 31
  • Joined: 16-August 08

Re: Install Directory

Posted 26 August 2008 - 09:06 PM

awsome thanks for the help!

Posted Image
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1