Reputation: 953
I have just finished a WinForms app, and its working great! Now, time to deploy. Issue is, that I dont want to create a setup file, but rather a single executable, for example 'myApp.exe'. The reason for doing this, is because it will be redistributed on CD media, and it is supposed to auto-run as a stand-alone app when the CD inserted into a user's PC.
Any thoughts here?
Secondly, how can I create a reference to '.txt' files contained on the CD from within the app? I want to provide links to the files, but Im unsure as to how to do the path reference.
TIA...Im really puzzled here!
Upvotes: 0
Views: 1141
Reputation: 44096
@Shalan, re: your answer:
Be careful! You'll upset your users and maintenance programmers!
I've seen and fixed this error at least a couple dozen times.
Are you sure you know what the current directory is? The OpenFileDialog and SaveFileDialog can change it, for example, and then you'd fail to find your .dot file.
What if the user starts the app with a different working directory? Then you'd also fail. Remember that you can't control your working directory-- your app will fail if the user changes it from the default.
If you must find the application executable's path, consider using Application.StartupPath along with System.IO.Path. E.g:
string dotSubPath = System.IO.Path.Combine("Assets", "MyDocument.dot");
string templatePath = System.IO.Path.Combine(Application.StartupPath, dotSubPath);
This will always get the path based on the application's startup directory, not just the working directory.
Upvotes: 1
Reputation: 953
For those interested, what also worked for me, where I needed a reference path from the application executable, was to use "Environment.GetCurrentDirectory"
So for example, I provided the path to my MS Word .dot Template as:
Object templatePath = Environment.GetCurrentDirectory + "\\Assets\\MyDocument.dot";
Upvotes: 0
Reputation: 560
When you reference the '.txt' files in your code, just use the relative path from where the app is being executed from. For example if your .txt files are in the same directory as the executable, refer to them without any path ("filename.txt") or you could use (".\filename.txt").
As far as not installing your app, just make sure you are not using any 3rd party libraries that would need to be installed on the clients and just burn the contents of your apps /bin/ directory and use an autorun.ini file to launch your exe.
Upvotes: 2
Reputation: 5823
You can use embedded resources within the exe instead of seperate files: http://jopinblog.wordpress.com/2007/11/12/embedded-resource-queries-or-how-to-manage-sql-code-in-your-net-projects/
Upvotes: 1