How do I load a string into a FileStream without going to disk?
For example,
string abc = "This is a string";
How do I load abc into a FileStream?
FileStream input = new FileStream(.... .);
Reason why I am doing this is that a method that I am calling expects a
FileStream but I would prefer to pass it a Filestream generated from a string
instead of a file since it would be extra overhead to create a file from the
string...... 5 12733
Look up the MemoryStream object
"Chris Fink" wrote: How do I load a string into a FileStream without going to disk?
For example,
string abc = "This is a string";
How do I load abc into a FileStream?
FileStream input = new FileStream(.... .);
Reason why I am doing this is that a method that I am calling expects a FileStream but I would prefer to pass it a Filestream generated from a string instead of a file since it would be extra overhead to create a file from the string......
Chris Fink <Ch*******@disc ussions.microso ft.com> wrote: How do I load a string into a FileStream without going to disk?
For example,
string abc = "This is a string";
How do I load abc into a FileStream?
FileStream input = new FileStream(.... .);
Reason why I am doing this is that a method that I am calling expects a FileStream but I would prefer to pass it a Filestream generated from a string instead of a file since it would be extra overhead to create a file from the string......
If you don't want to involve files, you don't want a FileStream. The
parameter to the method you're calling should almost certainly just be
Stream, not FileStream. If it's not, you're out of luck. If it is, you
should use a MemoryStream which wraps the results of Encoding.GetByt es
in whatever encoding you want to use.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Can I cast a MemoryStream to a FileStream?
"Jon Skeet [C# MVP]" wrote: Chris Fink <Ch*******@disc ussions.microso ft.com> wrote: How do I load a string into a FileStream without going to disk?
For example,
string abc = "This is a string";
How do I load abc into a FileStream?
FileStream input = new FileStream(.... .);
Reason why I am doing this is that a method that I am calling expects a FileStream but I would prefer to pass it a Filestream generated from a string instead of a file since it would be extra overhead to create a file from the string......
If you don't want to involve files, you don't want a FileStream. The parameter to the method you're calling should almost certainly just be Stream, not FileStream. If it's not, you're out of luck. If it is, you should use a MemoryStream which wraps the results of Encoding.GetByt es in whatever encoding you want to use.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
> Can I cast a MemoryStream to a FileStream?
Nope. Where would the FileStream find its FileName property?
But you can cast both to Stream.
Greetings,
Wessel
Chris Fink <Ch*******@disc ussions.microso ft.com> wrote: Can I cast a MemoryStream to a FileStream?
No, because it isn't one. A FileStream is always backed by a file -
that's why it's called a FileStream.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: BATISTA |
last post by:
Hi ,
I am working in c# with crystal report XI.
I read an example about dynamic image location ..
1) In that we have a xml xchema file with two fields n amed
country--datatype is string, img--datatype is base64Binary. using this as the
datasource,i have designed the crytal report. And a parameter is set asking
for the name.
2) I have designed teh form by adding a crystal report viewer and
|
by: Anbu |
last post by:
Hi,
I want to load contents of a remote HTML file and to display it on the ASP
..NET Web Page. The remote HTML file is not under any virtual folder and the
content & location may vary for each operations.
How can I do the same?
Thanks,
Anbu
|
by: Fred |
last post by:
Hello,
I am using a separate app domain to load an assembly from either disk
or cache, create an instance of it and run a method. I then call
dispose on the created instance and unload the app domain. This is
done in a web application. For some reason memory is not released and
continues to slowly but steadily grow. I tracked Working Set and
Private Bytes in Perfmon to check this.
Here is some example code:
|
by: Flemming Hansen |
last post by:
Hi guys,
I want to load a binary file in to an array by splitting the file in 8 bit
pieces. I mean:
FileStream s = new FileStream(path, FileMode.OpenOrCreate); // Open
StreamReader r = new StreamReader(s);
string data = r.ReadToEnd();
|
by: Bill Q |
last post by:
Hello,
this may not be the correct group for the post although I am using c# to
follow one of the code4fun directx tutorial. Anyway the author is
loading a texture file using the following
TextureLoader.FromFile ( _device, @"..\..\..\Resources\Left.tga"
I am not sure what the ..\..\..\ means when loading the file. I know
the directory the file lives in is C:\Documents and Settings\Bill\My
Documents\MSDN\BattleTank2005 (C#)\Resources
| |
by: =?Utf-8?B?VmVyZ2VsIEFkcmlhbm8=?= |
last post by:
Hi All,
I am using VB.NET 2003 and having problems with loading an xml file. Here's
my code:
Public Sub LoadXML()
Dim xmlDoc As New Xml.XmlDocument
xmlDoc.Load("C:\Databases.xml")
'more code follows here
|
by: Mike |
last post by:
Hi
I have problem as folow:
Caught Exception: System.Configuration.ConfigurationErrorsException:
An error occurred loading a configuration file: Request for the
permission of type 'System.Security.Permissions.FileIOPermission,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed. (machine.config) --->
System.Security.SecurityException: Request for the permission of type
|
by: Reg |
last post by:
I have a following code in HttpRequestListener's ProcessRequest method which
is a Windows
Console Application. I'm trying to read html page with browser (Opera) and
html file contains tags to include
Java Applet jar too,
for (int i = 0; i < numRequestsToBeHandled; i++)
{
HttpListenerResponse response = null;
|
by: Andrew |
last post by:
I am using an XmlSerializer to save some settings and I have discovered that
when a string is saved containing a cr+nl it is replaced with just a newline
when loading back in. I am no expert with XML and I wonder if there is a
option I have to change to fix this. I have written some simple test code
to show the problem.
Can anyone please tell me why the cr+nl is being replaced by just a newline
and how to stop this happening?
Thanks
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |