Getting additional files in LightSwitch
I want to add additional files (mostly .xlsx
and .docx
) to a LightSwitch application and use this files in the application, for example as a filestream.
What is the best way/practice to do this?
So far I can add files to the client-project (unde开发者_开发知识库r the file-view). This file then shows in the bin\debug\bin\Server
directory when I make a debug-build or publish the application. So now comes the tricky part.
How do I get a file stream of this files?
In which directory is it installed?
After hitting the post-button I figured it out myself. This blog post describes how to use embedded resources as images.
When you have added a file to the client-project, you have to set build action to “Embedded Resource” and then you can get a stream using the following code:
// get the currently executing assembly
Assembly assembly = Assembly.GetExecutingAssembly();
// list all available ResourceName's
string[] resources = assembly.GetManifestResourceNames();
// creates a StreamReader from the TestFile.txt
StreamReader sr = new StreamReader(assembly
.GetManifestResourceStream("LightSwitchApplication.TestFile.txt"));
// puts the content of the TestFile.txt in a string
string text = sr.ReadToEnd();
精彩评论