Superfly1611 Posted November 29, 2005 Posted November 29, 2005 Hello all, Out of nowhere i've been asked to write a small exe to distribute to our clients that will install some template files onto there computers. (Yes i've raised the issue of client's willingness to run foreign exe's on there computers). Now back in my uni days i remember hearing someone mention that you could compile a file(s) into an exe and then access them @ run time. Now I assume(???) that when compiling in .NET you set the Build Action to embedded resource to compile a file into your exe... but how do you then access this file? Many Thanks Quote
Cags Posted November 29, 2005 Posted November 29, 2005 (edited) Do you wish to simply access them to copy them into a location on the end users PC? If this is the case then (I'm kinda guessing here I've not tested it), I'm pretty sure creating a Setup / Deployment project might allow you todo this. It certainly allows you to copy files to specified folders on the clients pc, quite how well it works when your not actually installing an application I couldn't say, but I think thats the way I'd attempt to do it. EDIT:- I gave it a quick test and it did what I wanted, also has the added advantage of adding an item in the add/remove dialog. This would allow an end user to remove the templates. Edited November 29, 2005 by Cags Quote Anybody looking for a graduate programmer (Midlands, England)?
Winston Posted November 29, 2005 Posted November 29, 2005 I've done this before, basically you can add the file you want as a resource file into the solution, you gotta set it to compile in the exe, when needed, you can open the file as a temporary stream and write it to disk, as if it's copied, i'd advise you to keep all these templates as a class library so that way when u need to update them, you just update that particular dll. Quote
Leaders snarfblam Posted November 29, 2005 Leaders Posted November 29, 2005 Use the following code to get the streams... Imports System.Reflection '... Dim Assm As Assembly = Assembly.GetExecutingAssembly() Dim Stream As IO.Stream = _ Assm.GetManifestResourceStream("RootNamespace.Filename.withextension") 'here you can read from the stream and output the data to a filestream. Stream.Close() using System.Reflection; // ... Assembly Assm = Assembly.GetExecutingAssembly(); IO.Stream Stream = _ Assm.GetManifestResourceStream("RootNamespace.folderpath.Filename.withextension"); /* The folder path should be delimited with dots, not backslashes. Folder path is relative to the project's root folder. If the resource file is in the project's root folder, omit the folder path. */ // here you can read from the stream and output the data to a filestream. Stream.Close(); This is how it is done in .Net 1.0/1.1. As you can see, the resource naming conventions vary between C# and VB. I'm not sure that the naming convention has changed in 2.0, but 2.0 also has better tools for embedding resources, so you might want to click Help and do some MSDN research. Quote [sIGPIC]e[/sIGPIC]
Superfly1611 Posted December 3, 2005 Author Posted December 3, 2005 Thanks for u're help guys. Haven't had a chance to try this as i'm now being dragged onto another project... but i'm sure your help is all good :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.