tags:

views:

228

answers:

2

Hi,

Im using some code I found to open word docs from a webpage using c#. I have added the docs to the project as existing items, im just wondering the besy way to refer to them in the code,

eg

        object filename = "f:\\Online_signup1\\DONE-Signup_Step1.dot";

or just object filename = "DONE-Signup_Step1.dot"; thanks again

A: 

I'd put them all in a "Resources" folder or similar inside your project, add a Project Settings file ("app.config") which has the name of that folder, and then refer to them using that -
In your app.config file:

<setting name="DocumentDirectory" serializeAs="String">
     <value>F:\Online_signup1\Resources</value>
</setting>

Somewhere during program startup:

string docDir = Settings.Default.DocumentDirectory;

Everywhere else:

string filename = Path.Combine(docDir, myfile)

That way, if you ever distribute your program / move anything around, you won't be stuck going through your code and changing filenames everywhere, just change the directory in the settings file and you're golden.

For web projects, you can put it in the web.config file, like so:

<appSettings>
    <add key="DocumentDirectory" value="F:\Online_signup1\Resources"/>
</appSettings>

And access via:

string docDir = ConfigurationManager.AppSettings["DocumentDirectory"];
tzaman
can I put the <setting name="DocumentDirectory" serializeAs="String"> <value>F:\Online_signup1\Resources</value> </setting> in the applications web.config? If so should it be placed inside any other tag?thanks again
DarkWinter
Web.config works too - see my updated answer.
tzaman
A: 

check this useful link:

http://www.mindstick.com/Articles/956444a2-60c9-4d34-bb73-8c27039379d7/

dummy