简体   繁体   中英

C# get a stream from linked resource / content

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! :)

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#

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM