Reputation: 1933
I embedded some .txt files in the Resources folder. When I run the project, according to selection, the .txt file name is determined.
For example;
The file name is sample017.txt and I keep on textName string variable. This file's full path is :
"../../Resources\" + textName;
And I assign all of this to fileName string variable:
fileName = "../../Resources\\" + textName;
So, I use this string variable for streaming text file:
using (Stream input = File.OpenRead(fileName))
In this form, I can access to sample017.txt file and it works fine in Debugging mode.. But, when I build a setup project and install it any PC, It crashes into an Exception and it can't find the "Resources" folder. How do I manage the same using the Resources in the .exe file folder?
Note: I don't want to copy files to program folder. I want to embed these sources.
Upvotes: 0
Views: 940
Reputation: 478
Try to remove the ../.. from the path, because after deployment for resources is not the same as while debugging locally.
check also this thread:
Deployed application can't find its resources c# Visual Studio 2010
You could also embed your file as resource and load it using Assembly.GetExecutingAssembly. Use GetManifestResourseStream to get the content.
More details about accessing resources you find here: http://support.microsoft.com/kb/319292
Here is a snipped..
var assembly = Assembly.GetExecutingAssembly();
var res = assembly.GetManifestResourceStream("MyNameSpace.TextFile.txt");
var textStreamReader = new StreamReader(res);
regards
Upvotes: 1