开发者

Accessing resource/reference files from your final production program?

Please forgive me for my lack of C# knowledge!

How 开发者_JS百科do I access a required file at run time if I don't know where my application is installed/exists on the hard drive? Also- How do I distribute this file with my application (i.e., have it in a C:\Program Files\MyApp\resouces\file.ext)?

Background:

I'm using C# on .NET 3.5 with Spreadsheet Gears. My program writes out a series of excel files based on the contents of a database. One of the requirements is that the header in the page setup either needs to have an image or text with multiple colors/formatting. I've looked into both methods extensively and found no solution for doing this programmatically. My fall back is to open a prebuilt excel file which already has the logo in the header (you can do this from within excel), place the data into the excel file, and save it under a new name in a user specified place.

Should I be looking into resources or opening pre-set template excel files?

Thanks for all your help!


If the users of your Application have the right privilege, I would go with using Registry object to query Registry. I might have misunderstood your question - I presume you are asking for a way to find the path of the application?


The important thing is to make the name of the file relative, i.e. instead of:

C:\Program Files\MyApp\resouces\file.ext

have:

resouces\file.ext

and then have a small function that tries to open the file relative to the executable path, which you can get at run time. Don't open it based on the current folder as that can be different to the executable path.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜