views:

1020

answers:

5

Is there a way to display the contents from memory directly in a Notepad window?

+1  A: 

Double-click on the file, making sure the association is set to Notepad.

If you want Notepad to show it without saving it to disk, you can open an instance of Notepad, get the handle for the window, then write the text directly into there. You will need to use Windows User APIs to do this.

ck
Can you post me some sample code?
Rashmi Pandit
I don't have any to hand.
ck
ok np ... thanks for the idea though :)
Rashmi Pandit
+3  A: 

I'm assuming that I understand your question. If the file already exists on the machine you can execute the following:

System.Diagnostics.Process.Start( "notepad.exe", "[PATH]\[FILE].txt");

If not then save the file locally and then run the above code.

MrEdmundo
In case the file does not exist on the file-system, is it possible to open a notepad to display some in-memory text?
Rashmi Pandit
Why not save the file to a temporary directory?
MrEdmundo
Your question states you are READING A TEXT FILE, hence all answers telling you to open it in Notepad directly are correct. If this is not the case, change your question.
ck
A: 

Why do you need notepad to show some contents (which is in memory)?

If you are using winforms, you could put it in a textbox.
Sorry, if I have not understood your question correctly.

shahkalpesh
I dont need to. Just wanted to know if that is possible. I am doing some RnD using Console App
Rashmi Pandit
A: 

I would like to add to MrEdmundo's answer that the Isolated Storage is the right place to store the temporary txt file for Notepad.

Gerrie Schenck
Depends on the size of the file. Isolated storage has pretty low default limits for file sizes (1MB I believe).
Kent Boogaart
+1  A: 

The easiest way to accomplish this is to save the file and open it in notepad, however there are at least two other ways.

  1. Open Notepad then copy what you want to the clipboard, then using DDE force Notepad to paste. This is bad, because it potentially overwrites what the user may have been doing in the clipboard.
  2. The second way involves getting a window handle to the notepad Edit control, then doing a WM_SETTEXT to the window. This will not, however, work across privilege boundaries (such as for apps that run as administrator, but notepad runs as a normal user). This also involves getting down to Native level and doing P/Invokes. Not exactly an easy method.

Frankly, it's just easiest to save it to a file and load it.

Mystere Man