Getting the file path to a resource.

  • Thread starter Thread starter Andrew Cooper
  • Start date Start date
A

Andrew Cooper

Greetings,

I'm using a file called StatMonitorConfig in a program I'm writing and
I've added it as a Resource to the project. It's a text file. In my
program I need to get the actual location of that file when it is
installed on the users computer. How can I do this?

My.Resource.StatMonitorConfig returns the actual text of the file. I
need the file's location on the user's computer.

Thanks,

Andrew
 
Andrew said:
Greetings,

I'm using a file called StatMonitorConfig in a program I'm writing and
I've added it as a Resource to the project. It's a text file. In my
program I need to get the actual location of that file when it is
installed on the users computer. How can I do this?

My.Resource.StatMonitorConfig returns the actual text of the file. I
need the file's location on the user's computer.

System.Windows.Forms.Application.ExecutablePath


Armin
 
Greetings,

I'm using a file called StatMonitorConfig in a program I'm writing and
I've added it as a Resource to the project.  It's a text file.  In my
program I need to get the actual location of that file when it is
installed on the users computer.  How can I do this?

My.Resource.StatMonitorConfig returns the actual text of the file.  I
need the file's location on the user's computer.

Thanks,

Andrew

Not sure if it's the best way, but in the the past I've used:

System.Reflection.Assembly.GetExecutingAssembly.CodeBase

To get the path to the dll, and from that you can find your files.
Much easier to use the System.Windows.Forms method, but that one isn't
always (easily) available.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
 
Armin said:
System.Windows.Forms.Application.ExecutablePath


Armin

Armin,

Thanks. The problem with that is that when I use Build --> Publish to
publish the application and then install it elsewhere, the installer
doesn't actually put the resource in the same directory as my
executable. The path to the executable ends up being something like..

C:\Documents and Settings\acooper\Local
Settings\Apps\2.0\C631H4LC.O7N\BAL7BNDZ.NJZ\stat..tion_4a4e257f00226231_0001.0000_ba863c5628f914a9

While the path to the resource is...

C:\Documents and Settings\acooper\Local
Settings\Apps\2.0\Data\031PZ688.D4K\7MZND6VV.KW7\stat..tion_4a4e257f00226231_0001.0000_ba863c5628f914a9\Data

If there is someway to force the installer to put the resource in the
same directory as the executable that'd work too.

Thanks,

Andrew
 
Andrew said:
Armin,

Thanks. The problem with that is that when I use Build --> Publish to
publish the application and then install it elsewhere, the installer
doesn't actually put the resource in the same directory as my
executable. The path to the executable ends up being something like..

C:\Documents and Settings\acooper\Local
Settings\Apps\2.0\C631H4LC.O7N\BAL7BNDZ.NJZ\stat..tion_4a4e257f00226231_0001.0000_ba863c5628f914a9

While the path to the resource is...

C:\Documents and Settings\acooper\Local
Settings\Apps\2.0\Data\031PZ688.D4K\7MZND6VV.KW7\stat..tion_4a4e257f00226231_0001.0000_ba863c5628f914a9\Data

If there is someway to force the installer to put the resource in the
same directory as the executable that'd work too.

Maybe there's something I don't know but a resource is embedded in the
executable. That's the purpose of a resource. I don't know how it can get to
another place. I'd have to extract the resource and save it to a file in
order to not have it in the assembly only. In the properties windows, after
selecting the resource in the project explorer, I've always chosen "embedded
resource" as the value for the "build action" property. I don't have
experience with other settings but then I don't call it a resource.


Armin
 
Back
Top