473,750 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open wordpad/notepad file

Thank you in advance for any and all assistance. It is greatly appreciated.

I would like a command button in VB.Net 2002 to open a text file, then to allow
text from a textbox on the current form to be appended to that text file. Is
there a place where I can see code to do this?

I have the data/text on the clipboard using the clipboard class, now I want to
append it to the text file either in Notepad or Wordpad. I have tried using the
StreamWriter and get that it's undefined under the Private_Sub Function of the
command button. What am I doing wrong?

Michael
Nov 20 '05 #1
7 13190
* lu************* @aol.com (Lumpierbritche s) scripsit:
I would like a command button in VB.Net 2002 to open a text file, then to allow
text from a textbox on the current form to be appended to that text file. Is
there a place where I can see code to do this?
\\\
Dim p As Process = Process.Start(" notepad")
Try
AppActivate(p.I d)
Catch
End Try
Clipboard.SetDa taObject("Hallo Welt") ' Text in Clipboard setzen.
SendKeys.Send(" ^v") ' Strg+V auslösen.
///
I have the data/text on the clipboard using the clipboard class, now I want to
append it to the text file either in Notepad or Wordpad. I have tried using the
StreamWriter and get that it's undefined under the Private_Sub Function of the
command button. What am I doing wrong?


You will have to import the 'System.IO' namespace ('Imports System.IO'
on top of the file). Notice that this won't make any sense if you want
to append the text using Notepad or Wordpad.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
How do you consider this is a solution. I have no idea what you're talking
about. I just wanted to know, in code, how to open a text file and append text
from a field on a form, using the clipboard paste, from a command
button>?>>>>>?? ??

Michael
Nov 20 '05 #3

"Lumpierbritche s" <lu************ *@aol.com> wrote in message
news:20******** *************** ****@mb-m21.aol.com...
How do you consider this is a solution. I have no idea what you're talking about. I just wanted to know, in code, how to open a text file and append text from a field on a form, using the clipboard paste, from a command
button>?>>>>>?? ??

Michael


It is the colution you asked for. You asked how to open a notepad/wordpad
file, then vaguel amended it to open a text file. I believe what you are
looking foris reading/writing to a text file. You are correct in using a
StreamReader/StreamWriter, but, if it's not defined, look at where you
defined it in code. You must always be aware of the scope of your object
declerations. Consider the following:

Private Sub Main
Dim SR As StreamReader
End Sub

Private Sub WriteFile(ByVal Input As String)
SR = New StreamReader("C :\somefile.txt" )
MyText = SR.ReadToEnd
SR.Close
End Sub

You will get your Undefined Error because WriteFile sub has no clue what
SR is because it's declared in Main sub. This has never changed in any
language I know of, but, under VB6, it would have been made a varient unless
you had Option Explicit on, which is default under .NET, then you'd get an
Unefined Error. The two solutions are to either define SR as a FormLevel
object, by this I mean outside of any procedure, or as a Procedure level
object. Now, something to consider, FormLevel objects always exist in
memory as long as the form does, so, if you only need it once or twice, make
it procedure level and the GarbageCollecto r will gett ride of it when you
don't need it and thus free up resources for other objects. NOTE: my
discription of the Garbage Collector is not entirely accurate, but the gist
is correct.
So, IMHO, try tthis code:

Private Sub WriteFile(ByVal Input As String)
Dim MyText as String
Dim SR As StreamReader = New StreamReader("C :\somefile.txt" )
MyText = SR.ReadToEnd
SR.Close
Dim SW As StreamWriter = New StreamWriter("C :\somefile.txt" )
SW.Write( MyText & Input)
SW.Close
End Sub

This will read in the textfile, and write it right back out. Now, another
nifty trick of the StreamWriter, open it and Append to the file, eliminating
the StreamReader all together. Check into it. They are both in the
System.IO namespace.

HTH
Sueffel
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.580 / Virus Database: 367 - Release Date: 2/6/2004
Nov 20 '05 #4
Mr Lumpier Britches,

Mr Wagner gave you an accuracte answer for your questions. The code he
posted will paste the current clipboard content into the notepad.

What more do you want ?
OHM

Lumpierbritches wrote:
How do you consider this is a solution. I have no idea what you're
talking about. I just wanted to know, in code, how to open a text
file and append text from a field on a form, using the clipboard
paste, from a command button>?>>>>>?? ??

Michael


--
Best Regards - OHM
one.handed.man{ at}BTInternet{d ot}com
Nov 20 '05 #5
* lu************* @aol.com (Lumpierbritche s) scripsit:
How do you consider this is a solution. I have no idea what you're talking
about. I just wanted to know, in code, how to open a text file and append text
from a field on a form, using the clipboard paste, from a command
button>?>>>>>?? ??


Mhm... That's exactly what the code I posted is doing. It starts
Notepad and pastes some text into it using the clipboard.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
Thank you everyone. In VB 6, you could just use Shell and open a word / notepad
file and then using Keystrokes go to the end of the file and paste the
clipboard.

I'm just trying to take a command button and have code open a word/notepad file
and append some text in a form textbox, that's on the clipboard to a text file.

I'm not a fulltime coder, just playing with it for some personal use. When I
put any code in the button click event, I get undefined on Streamwriter or
reader. I'm going to try new things, but I was looking for a simple:
shell:(c:\progr am file\myfile.txt )
^{end}
^V
or something similar.

But, again, thank you for all your help. I'm just frustrated with .Net. It's
not anything like VB6, which took me awhile to get coding down in it.

Michael
Nov 20 '05 #7
* lu************* @aol.com (Lumpierbritche s) scripsit:
reader. I'm going to try new things, but I was looking for a simple:
shell:(c:\progr am file\myfile.txt )


Use 'System.Diagnos tics.Process.St art(<filename>) ' instead.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #8

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

Similar topics

4
107957
by: Jesper | last post by:
How can I open a textfile from C# using notepad (or the user assigned application for this).
7
1642
by: Hareth | last post by:
When VS2003 is installed : I can open Form1.cs w/ windows "open with" contextmenu, then it opens the file w/ notepad & it works fine but after installing VS2005, "open with" doesnt function correctly. If I try to open with notepad, it forces an open to VS2005
3
4857
by: RN Das | last post by:
Hi expert, I have a small web application in C# and ASP.Net and I want to open a file in notepad when clicked on a linked button. Here is hander code when clicked on the link button. It can open a process of notepad on the server , but does not open the file in notepad. What am I doing wrong? can you show me how to do it please? What I am doing here is : I have datagrid data and when clicked on linkbutton (logFile), it finds the row...
4
4279
by: Lorimer | last post by:
Thanks in advance for any help received. Is it possible to automatically display a text file in Wordpad using VB.NET and if so how do I do it? Thanks again L
9
4322
by: Dino Buljubasic | last post by:
If I want to delete a file I can call File.Delete(filePath) but what happens if I am trying to delete the file that is open??? In java you would do someting like int status = fileExists(filePath) // return 0, 1, or 2 2 means file exists and it si open but VB returns boolean value telling file exist or not
2
1921
by: GW | last post by:
After the conversion and fixing some errs VS2005 threw, project ran OK. Opened xxx.vbproj file after the conversion to VS2005 from VS2003. Changed (usng wordpad) ../msbuild/2003 to 2005 thinking that should read 2005 Unable to open project after that. Chgd back to 2003. Unable to open. Err unable to read xxx.vbproj(218,16)
6
3107
by: Moumen VB.NET 2003/2005 Developer | last post by:
How can I detect if a file sitting on a network drive is still open by another application? This application resides on another machine on the network? I am using VB.NET 2003 Your help is highly appreciated
11
5602
blyxx86
by: blyxx86 | last post by:
Alright, I'm trying to create a form that would allow certain documents to be opened by selecting an option within a combo box and then having a single button to open the pertaining file. I know how to have it open an excel document (or word, etc.) but do not know how to define which document to open. Dim ExApp As Object Set ExApp = CreateObject("Excel.Application") ExApp.Workbooks.Open FileName:="c:\file.xls",...
6
9290
by: =?Utf-8?B?TUNI?= | last post by:
I try to open a log file that is logging infomation by another process: StreamReader sr = File.OpenText(filePath); I got the exception message: The process cannot access the file 'c:\temp\myLog.txt' because it is being used by another process. How can I open, read and process the file in C#?
0
9577
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...
1
9339
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,...
0
9256
tracyyun
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...
0
8260
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...
0
6081
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
4713
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
4887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
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
2
2804
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.