473,695 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Want to create either a stream or a file

I am reworking a class that generates source code. I want to add a
"preview" function, much like the refactor dialog in vs2005. To facilitate
this, I have changed what used to be my "writeToFil e" method to "generate" -
the plan is, I will generate the text in memory, then I can either show it
in a control or pass it to the method that does the file IO stuff.

I'm trying to determine the best class' to use for this, I was hoping there
was something that would let me build the string, then pass it to a writer
class, but I haven't found it yet. Currently I'm using StringWriter to
generate the source, then when I want to write the code, I use
StreamWriter.Wr ite() passing it my StringWriter.To String();

This seems ugly to me. Is there another way that would be cleaner? I was
hoping for something like setting a StreamWriter's internal data to my
StringWriter, or casting a StringWriter to a StreamWriter... something like
that. They seem so closely related.

Any ideas?

Thanks for reading,
Steve
Dec 13 '05 #1
1 1318
Steve,

I would have your generate method take a TextWriter. That way, if you
want it in a string that you can get later, you can pass a StringWriter. If
you want to write it to a file, then you can use a StreamWriter instance
with a FileStream backing it.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Steve" <ss*@sss.com> wrote in message
news:ut******** ******@TK2MSFTN GP11.phx.gbl...
I am reworking a class that generates source code. I want to add a
"preview" function, much like the refactor dialog in vs2005. To facilitate
this, I have changed what used to be my "writeToFil e" method to
"generate" - the plan is, I will generate the text in memory, then I can
either show it in a control or pass it to the method that does the file IO
stuff.

I'm trying to determine the best class' to use for this, I was hoping
there was something that would let me build the string, then pass it to a
writer class, but I haven't found it yet. Currently I'm using
StringWriter to generate the source, then when I want to write the code, I
use StreamWriter.Wr ite() passing it my StringWriter.To String();

This seems ugly to me. Is there another way that would be cleaner? I was
hoping for something like setting a StreamWriter's internal data to my
StringWriter, or casting a StringWriter to a StreamWriter... something
like that. They seem so closely related.

Any ideas?

Thanks for reading,
Steve

Dec 14 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3054
by: Anders Olsson | last post by:
I need to create a StreamReader which starts from the position of an existing StreamReader. This way, the second StreamReader can read lines "ahead" in an own loop, and then I can go back to the outer loop and the first StreamReader is still where I left it. I have been trying to do this using this code: StreamReader sr2 = sr1 //Where sr1 is the existing StreamReader This seems to work just fine, so I guess this is a supported way...
11
2186
by: Brian W. Smith | last post by:
I have XML Documents that I am digitally signing, and need to be able to load these documents into DataSet objects. However, after checking the signature and using the DataSet.ReadXML method, I am getting an exception "The root element is missing". I have struggled over the last 24 hours trying to figure out ways of correcting this, however I am stuck. I would appreciate any help that the community can provide me on this. Thanks,
3
2628
by: Peter | last post by:
Hello! Please, could you tell me, is it possible to create and stream for example a text file to the browser so that the file is not stored anywhere on a hard drive? User click's a link, eg. http://my.domain.com/apps/app/page.aspx?docID=235 and then the text file opens with a text "235" and when the user closes the file there is not track of the file anywhere on a hard drive.
2
1456
by: matt | last post by:
hello, i have what i would guess to be a relatively "newbie" question: how do i create & write to a new text file? i have found plenty of articles (MSDN & other) on how to do this in conjuction w/ the *file system*, but i do not wish to touch the client's hard drive. rather, id like to build up a .txt file in memory, then Response.WriteFile() it back to the user (ASP.NET plaform).
1
4514
by: tofu.captain | last post by:
I have PDFs saved in a SQL 2005 server as BLOBs. I would like to extract the BLOBs and either: 1. create a PDF file on the hard disk or 2. open/stream the PDF into the application I am using a VB.net winform (not a web form). How would I go about doing this? I use CutePDF to initially convert a
6
1833
by: Parrot | last post by:
I am using WebClient to download a file from a server in my webpage. How can I create a dialog that asks the client for a download path? Now I am just hardcoding a directory path for the following command: myWebClient.DownloadFile(myStringWebResource, fileName); I guess I am looking for a download version of the FileUpload control. Anyone know how to do it like the big boys do? Do I need to use javascript?
8
2231
by: paraidy | last post by:
Hi all, as from object i need to read all byte from a file example c: \myphoto.jpg and recreate the file with another name to another directory c:\photo\recreatedphoto.jpg can someone write a small example to do it? thx a lot men :)
4
6907
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the function creates the file as expected. When I loop through my array I get the error - "ArgumentException was unhandled - Illegal characters in path" The value "C:\Temp.txt" is the first value in the array - as it works
4
16664
by: nano2k | last post by:
Hi For some purposes, I need to create a new binary file and to allocate a fixed length for that file on the disk. I need something like File.Create(string fileName, long initialSizeInBytes). Is there a framework/system method to do that or should I create the file and then fill it until the size is reached? Thanks
0
8587
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9140
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6511
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5847
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();...
0
4351
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...
0
4599
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2291
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1987
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.