在 LightSwitch 中获取其他文件 [英] Getting additional files in LightSwitch

查看:30
本文介绍了在 LightSwitch 中获取其他文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向 LightSwitch 应用程序添加其他文件(主要是 .xlsx.docx)并在应用程序中使用这些文件,例如作为文件流.

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?

到目前为止,我可以将文件添加到客户端项目(在文件视图下).当我进行调试构建或发布应用程序时,此文件将显示在 bin\debug\bin\Server 目录中.所以现在是棘手的部分.

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?

安装在哪个目录?

推荐答案

在点击发布按钮后,我自己想通了.这个 博客文章 描述了如何将嵌入的资源用作图像.

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

这篇关于在 LightSwitch 中获取其他文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆