Reputation: 9
When publishing the WPF application and generate an exe, I am unable to get the files which are placed in the templates-folder. When I copy my folder and files to bin it works, or if use
string StartUpPath = AppDomain.CurrentDomain.BaseDirectory.ToString();
// var gparent = Directory.GetParent(Directory.GetParent(Directory.GetParent(StartUpPath).ToString()).ToString()).ToString();
ReportDocument reportDocument = new ReportDocument();
StreamReader reader = new StreamReader(new FileStream(StartUpPath + @"\Templates\Invoice.xaml", FileMode.Open));
This code works fine for my local, but when I generate an exe, these files are not found.
Upvotes: 0
Views: 314
Reputation: 1223
That's because your files aren't in the exe. I had the same problem recently.
It sounds like you need to handle your resources - there are several ways to go about this, and Microsoft has a full explanation here about resources, including the difference between using Linked and Embedded Resources, and links through to other great guides.
I'm assuming you're using Visual Studio, in which case this should work;
ALT
+ ENTER
)Resource
Copy if newer
... and you should be good to go.
Upvotes: 1
Reputation: 5715
I think it throws an exception because the file doesn't exist on that machine. You can set Build Action
to Content
and Copy to Output Directory
to Copy Always
or Copy If Newer
on property window.
These settings will make sure that you have the file to your output.
Upvotes: 0