Solved

Create A file but not a physical file

Posted on 2004-04-07
3
352 Views
Last Modified: 2010-04-15
Is there a way in C# to create a file, but never actually write it to disk. Just to create a small temporary file that would only be held as an object within the application. (I know this is a strange one) but it would make an application of mine much faster as I need to pass small files frequently, and it has to be files.
0
Comment
Question by:jj819430
3 Comments
 
LVL 6

Expert Comment

by:DaniPro
ID: 10773102
Yes, you can use the System.IO.MemoryStream class that stores the information in memory and not in a file.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 10773143
You can use the MemoryStream Class. Create instance of MemoryStream Class and fill it using Write* members. After this it can be used for reading using Read members.
For example, StreamReader class instance may be initialized from file name:
public StreamReader(
   string path
);
or stream:
public StreamReader(
   Stream stream
);

You can initialize StreamReaded from MemoryStream instance and read it exactly as file.
0
 
LVL 7

Author Comment

by:jj819430
ID: 10773426
Awesome. I won't get around to plugging this in for another 12 hours or so, but sounds like a reasonable answer so will give you the points.
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question