2011-09-26 22 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();