Getting the file path to a resource.

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
 
A

Armin Zingler

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
 
R

rowe_newsgroups

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/
 
A

Andrew Cooper

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
 
A

Armin Zingler

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top