How to save changes of a saved text file in VB.NET - vb.net

I have a text editor that can open text files .txtand puts the text in a textbox. The user can also save the text to a .txt file.
How can the user save the changes of that text file that was saved recently?
Also, If the user opened a txt file how can the text editor change the text file to what the user changed?
Hope you understood that. Thanks in advance.

Since I don't know what you've done so far I will take this from the beginning...
For this you will need these components:
A SaveFileDialog
An OpenFileDialog
Three buttons (or menuitems), labeled: "Save", "Save As", "Open"
And I actually recommed using a RichTextBox instead of a regular TextBox.
.
To start, we put a variable in the code to know what file was saved before:
Dim LatestFile As String
Then, go to the properties of your Save- and OpenFileDialog and put this in the Filter field:
Text files (*.txt)|*.txt
Then you double-click the SaveFileDialog which should write the SaveFileDialog_FileOk event in your code. There you put:
LatestFile = SaveFileDialog1.FileName
RichTextBox1.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
And then double-click the OpenFileDialog, and enter this code:
LatestFile = OpenFileDialog1.FileName
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
And then for the buttons:
The "Open" button:
OpenFileDialog1.ShowDialog()
The "Save" button:
If Not LatestFile = "" Then
RichTextBox1.SaveFile(LatestFile, RichTextBoxStreamType.PlainText)
Else
SaveFileDialog1.ShowDialog()
End If
And the "Save As" button:
SaveFileDialog1.ShowDialog()
.
Hope this helps!

If I understood your question: you want your text editor application to detect changes that happened to the source text file that it is currently viewing to the user and if it detects a change, it should update its text box to display the latest file for the user.. am I right?
If that is the case, one way to do that is to use a Timer. Every time the timer tick event is triggered, you should check the date of the last modification to the file. If it is greater than the date that you have checked while opening the file for the first time, then the file had gone through some changes. Reload the file contents into the text box.
Another way (without using Timers) is to only check for the modification date once the application window is activated. Since the user will have to change the focus of the program to, say Notepad to do changes to the text file, then once the user returns focus to the Text Editor Application, use the Window Activate or Click event to check the file modification date.

Related

How to save textbox text to notepad and save again a textbox text to add it into the same note pad?

I want to save my textbox1.text in a notepad of my computer. And after saving that, I will save the next textbox1.text again. But I want it to be added to the same notepad. Anyone can help me on the code? Using VB net.
I have a one form with controls and all entries will be displayed on one textbox. I want to save that textbox but I don't know how.
You could use the File.AppendAllText method to save the text to a file:
Public Sub SaveTextToFile(FilePath As String, Text As String)
System.IO.File.AppendAllText(FilePath, Text)
End Sub
Here is an example of using the method:
SaveTextToFile("C:\New.txt", textBox1.Text)

Show file input when click button event on LotusScript?

I am working with Lotus Domino. When I read the xml file I want to click on a button and it displays a form to let me select the file:
Sub Click(Source As Button)
//How to file input form display here
End Sub
There's still one more problem.I read the xml file and output data is documents:
Dim reader As New XmlNodeReader
Call reader.ReadFile(datas)
documents = reader.getNodeReaders("egov.document ")
Forall document In documents
//How to display list document for my form
End Forall
Please help me in the shortest possible time.Thanks all!!!!
To display a dialog that allows you to select a file, use the Prompt method of the NotesUIWorkspace class.
The rest of your question requires knowledge of the particular XML schema you are working with.

Create OpenFileDialog when RichTextBox selected?

In my application, a list of fields is read from a database, and then rendered in a TabControlPage. Each field has a Control of a specific type, one of which is a RichTextBox.
What I need, is when the user selects the RichTextBox, an OpenFileDialog should appear, allowing the user to select a file. The RichTextBox should then display the full path + filename(eg. C:/files/excel/thing.xlsx) in the form of a hyperlink.
Currently, you can type in the path+filename into the RichTextBox and it will automatically be made into a hyperlink.
Any suggestions, or perhaps reference material you can give me?
You can attach something like this to the Enter event on your RichTextBox:
Dim dialog As New OpenFileDialog()
Dim result As DialogResult = dialog.ShowDialog()
If result = Windows.Forms.DialogResult.OK Then
RichTextBox1.Text = dialog.FileName
End If
This is not turning it into a hyperlink for me, but it sounds like you have that part handled?
edited as per Lars' comment.

How to Open Notepadd ++ With Textbox.text?

I have a small program that I am working on that grabs a script within an object model. I can get the script to display in the text box and I can get notepad++ to launch on button click.
What I would love to do is have the text from the text box open inside notepad++ so that i may edit the script.
Does anyone out there have any ideas?
Save the text from your text box to a file, like this:
System.IO.File.WriteAllText("path and name of text file.txt", textBox1.Text)
Now you can force the user to use Notepad, by doing this:
Process.Start("path to notepad.exe", "path and name of text file.txt")
Or you can have the system determine what the user's preferred application (say they have Notepad++) is for a .txt by doing this:
System.Diagnostics.Process.Start("path and name of text file.txt")

Use Applescript to pass Path and File Name to Save as Print Dialog box for PDF's

I have a script that opens an email and then I want to save it as a PDF. The script works but I cannot figure out how to pass the path and folder name to the dialog box that results after I call Save as a PDF. This is my script so far.
global FlName
tell application "Mail"
set theMsg to selection
open selection
set Dialogresult to the button returned of (display dialog "Process this email and Print as PDF" buttons {"Yes", "No"} default button "Yes")
if Dialogresult is "Yes" then
repeat with selectMsg in theMsg
tell selectMsg
--set background color to red --Show message processed
set FlName to subject
set check to count every word of FlName
--display dialog check
set FlName to (my FixFileName(FlName)) --strip bad characters
end tell
end repeat
set process_name to "Mail"
activate application process_name
tell application "System Events"
tell process process_name
--display dialog "proposed File Name" & return & FlName
keystroke "p" using command down
delay 2
set PDFref to sheet 1 of window 1
click menu button "PDF" of PDFref
click menu item "Save as PDF…" of menu 1 of menu button "PDF" of PDFref
tell application "Mail"
display dialog "Proposed Name " & my FlName default answer FlName & "change in the Box if Not OK"
set FlName to text returned of result
end tell
keystroke FlName
end tell
end tell
else
set Dialogresult to the button returned of (display dialog "Close this eMail" buttons {"Yes", "no"} default button "No")
if Dialogresult is "Yes" then
close window 1
end if
end if
end tell
on FixFileName(str) --Deletes characters that cannot be used in file names
set fixed_string to {}
set bad_char to {":", "/"}
repeat with c from 1 to (count every character in str)
if bad_char contains (character c of str) then
set end of fixed_string to "-"
else
set end of fixed_string to (character c of str)
end if
end repeat
fixed_string as string
end FixFileName
Peter
One other possiblity to consider is writing a separate PDF Applescript and adding it to the PDF pulldown menu via "Edit Menu". (Not sure what application you would have to TELL... Check out this link for a lead: http://hints.macworld.com/article.php?story=2004122222145585) Here's the excerpt from Mac Help:
You can add your own items, such as applications and AppleScript
scripts, to the PDF pop-up menu. For example, you can add an
AppleScript script that applies a Quartz filter to a PDF file, or you
can add an application that opens the PDF file immediately after it’s
created.
If you create a Print workflow plug-in in Automator, that plug-in is
added automatically. For more information, open Automator, choose Help
Automator Help, and search for “Print workflow plug-in.”
To add an item to the PDF pop-up menu:
Choose File > Print.
Choose Edit Menu from the PDF pop-up menu.
Click the Add (+) button and select the item you want to add.
For example, if you want to open a newly created PDF file in Adobe
Acrobat, select Adobe Acrobat. If you’ve created an AppleScript script
that applies a Quartz filter to a document, choose that script.
An alias to the item is saved in the PDF Services folder in your
Library folder.
If you're unable to set the name of the PDF when it's generated, but know where it was saved and what it was saved as, use AppleScript to rename and move the file to where you want instead. It might be kind of kludgy to select the location and the name, using a display dialog to let the user choose the name and a choose folder to allow them to select the location.
Following #Chuck's answer, yes that is kind of kludgy, but there is the choose file name command, which lets the user choose the name as well as the location...
set the FlName to (choose file name with prompt "Choose a name and location for the new PDF document:" default name "untitled.pdf")
However, this does not actually create the file. The commands below do.
open for access FlName
close access FlName