2013-05-07 93 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) %>