Getting additional files in LightSwitch

拜拜、爱过 提交于 2019-12-23 01:43:09

问题


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 (under 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?


回答1:


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();


来源:https://stackoverflow.com/questions/7562386/getting-additional-files-in-lightswitch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!