2011-09-26 77 views
1

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

这样做的最佳方式是什么?

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

如何获取此文件的文件流?

在哪个目录中安装?

回答

1

点击后按钮后,我想出了自己。这blog post描述如何使用嵌入的资源作为图像。

当您添加文件到客户端的项目,你必须设置生成操作为“嵌入的资源”,然后你可以用下面的代码获取流:

// 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(); 
相关问题