william007
william007

Reputation: 18545

Where to put the external file in a project

I have a dataset file a.txt where I want to include as part of the visual studio 2010 C# project. Where should I put it(need your suggestion), and how should I read it with FileInfo (as project might move around the PC by different developers, it is not good to have hardcoded path)?

Upvotes: 0

Views: 84

Answers (1)

Orn Kristjansson
Orn Kristjansson

Reputation: 3485

You could put it in /resources or some dir you create from root. Then you can read it at runtime from

System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) + "\\resources" 

or you can embed is a resource, then you can use

Assembly.GetManifestResourceStream(string)

more info on that here How to embed a text file in a .NET assembly?

Upvotes: 1

Related Questions