2013-05-07 69 views
0

我一直在玩MVC和本地化的多語言網站。恰巧我也有本地化的下載(使用不同語言的說明)。我想:資源也可以包含文件,爲什麼不把它們放在那裏?輕鬆說完,但現在我的問題是:如何從資源文件中提取文件,以便用戶可以打開或保存它們?MVC 4 - 從資源下載本地化文件,如何?

我是否使用ResourceManager.GetObject("filename in resource", what type will it be?)ResourceManager.GetStream("filename in resource", what type will it be?)以及如何將它們作爲文件返回?

我一直在尋找this後,但我不知道這是我需要什麼?

回答

0

我做到了。根本不需要ResourceManager

在我的控制器:

public FileResult Download(string filename) 
    { 
     byte[] fileBytes = null; 

     switch (filename) 
     { 
      case "Flyer Instructie.pdf": 
       fileBytes = Resources.Resources.Flyer_Instructie; 
       break; 
      case "Flyer Front.pdf": 
       fileBytes = Resources.Resources.Flyer_Front; 
       break; 
      case "Flyer Back.pdf": 
       fileBytes = Resources.Resources.Flyer_Back; 
       break; 
     } 

     return File(fileBytes, MediaTypeNames.Application.Octet, filename); 

    } 

在我看來:

<%: Html.ActionLink(Resources.DownloadsInstructionText, "Download", "Home", new { filename = Resources.DownloadsInstructionLink }, null) %>