0

I have some "heavy" files (.csv of 50 MB) and I would like get a stream from them knowing that I would like to avoid building them as "embedded resource" (one of my requirements). These files are accessed only by one class, so it is not a complicated situation. In the end, my solution will end up as a .dll.

I would like to know what is the best way to do so:

1) What is the best Build action, content or (linked) resource?

2) how do I get a stream from my resource?

I have been searching a lot on the internet and none of the solutions I have found work on my case:

  • I have tried to access them by the resourceManager but if I understand well, it is just for embedded resources

  • Another solution is to use Application.GetResourceStream but I can't access to the Application namespace, I don't really know why (I added using System.Windows but it does not solve the problem)

So far I have been trying these solution by using a testMethod, I don't know if it has an impact on the problem.

Thanks! :)

Community
  • 1
  • 1
G_L
  • 3
  • 4
  • Is there a particular reason, why you must not go for a embedded resource? – nozzleman Jun 29 '15 at 06:59
  • For what I have understood of embedded resources, they are stored in the virtual memory and I would like to avoid that (the program is already quite big). – G_L Jun 29 '15 at 07:06

1 Answers1

0

If the files are 50Mb I would not embed them into the DLL unless it is very unpractical to deploy the DLL with the extra files.

So Content would be my choice. 50Mb is not much and would fit nicely, but remember that the DLL is loaded into memory, so it will affect the memory usage. I would never add a 2Gb embedded resource into my DLL! :P

Streams are streams. And since these would be external files it would be file streams you are after. Take a look at this thread for reading your CSV as a stream: Reading large text files with streams in C#

Community
  • 1
  • 1
Wolf5
  • 16,600
  • 12
  • 59
  • 58
  • Thanks @Wolf5 for your fast reply! It works (I think I was searching a complicated solution whereas that works just fine using simple ones...)! I also encountered a problem to test my code using Unit Test (I could not find the data), to solve that I had to deploy my data in the output folder using the [DeploymentItem("Resources", "Resources")] tag (deploys the data contained in the "Resources" folder of my solution into a folder called "Resources" in the Unit Test folder). – G_L Jun 29 '15 at 08:17