I've been playing around with MVC and localization for a multilingual site. It so happens I also have localized downloads (instructions in different languages). I thought: a resource can also contain files, so why not place them there? Easily said and done, but my question now is: How do I extract the files from the resource file so users can either open or save them?
Do I use ResourceManager.GetObject("filename in resource", what type will it be?)
or ResourceManager.GetStream("filename in resource", what type will it be?)
and how do I return them as file?
I've been looking at this post but I'm not sure if this is what I need?
I did it. Didn't need the ResourceManager
at all.
In my Controller:
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);
}
And in my View:
<%: Html.ActionLink(Resources.DownloadsInstructionText, "Download", "Home", new { filename = Resources.DownloadsInstructionLink }, null) %>