• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

C# embedded files

LBJuice

n00b
Joined
Jan 23, 2005
Messages
27
I have an embedded file I need to reference. The file is a .dot (word Template). The Program is a form where the user fills out a form and it generates a Doc file with the values inserted. I'm embedding the template because it needs a location to call the file from and since it will be deployed.. it cant be from a static directory. excuse me if this is making little sense I been up all night (its 6a and class at 9:35a) trying to figure this out. If you know of a way to include the file and give the app. a relative path that works too, however, when I tried that in the past, once I "publish" the app it runs it from a \Documents and settings\local files\ path, its a setup not a flat exe.
 
In Win32, this was pretty easy. In .NET, it's a mess becasue the CLR team, for dubious reasons, completely recreated the resource system that Win32 had and replaced it with something that doesn't work nearly as well.

You'll end up adding a resource to your executable image, which you can do in Visual Studio with the Resource designer. When you do that, a link will be made between your project and the file, so you'll want to have a copy of your file in the project directory. That is, don't just browse to the file wherever it exists on your hard drive now; take a copy and move it to your project directory.

After adding the file to your resources in Visual Studio, you'll find that the resources designer has added a mmeber to your application's Resources class so you can access that resource. For a binary image, you'll get an internal static method that returns a byte[], which is all the bytes in your resource.

Fo your application, it sounds like you'd want to grab that array then write it out to a file for the user (or hand it to whatever code you have that builds the Word document you want).
 
Instead of using embedded resources which are a pain (I know from experience), why don't you just deploy the template with the application using the setup project. You can get the path of your executable at runtime and pull the file from that folder or subdirectory contained within. Kinda makes it easier for updates as well since you don't have to redeploy the the application for a template change.
 
Back
Top