VB 2010 - Button that opens DEFAULT email program and populates entries from txtboxes - vb.net

I've created a form in VB that requests some entries and through those entries a body for an email is created. Now I have to make a button that opens the default email client of the computer and populates the Body with the text that is generated through the form (I don't want it to send the email since the user is supposed to add the From and the Subject). I've managed to make it happen through this simple line :
Dim Text As String = Textbox1.Text
Process.Start("mailto:email#email.com?subject=Hello&body=" & Text)
However, when the email client opens the format of the body is messed up. There are supposed to be paragraphs and spaces but there aren't any. Can you help me fix this ?

In order for MailTo to work properly, you need to URL Encode your message. The following should work:
Dim Text As String = Textbox1.Text
Process.Start("mailto:email#email.com?subject=Hello&body=" & System.Web.HttpUtility.UrlEncode(Text))

Related

Search text file and put matching results in listbox

I have a VB.NET project in which there is a form where there is a TextBox control, a ListBox control and an external text file that contains a list of outlook folder paths for client emails.
Essentially, the user enters into the text box the name of a client and/or their unique reference number, presses the search button (yes - I know I could make the results appear as they type, I want a button!) and it comes up with the matching results for the company name or serial number that are in the text file and puts them in the list box, with the full path of the outlook email folder.
For example:
If I put into the textbox: "06967759-274D-40B2-A3EB-D7F9E73727D7"
It would put the following result into the listbox:
"EIS Admin\Contacts{06967759-274D-40B2-A3EB-D7F9E73727D7}"
And the user can then go to that folder and find the email(s).
I have gone through several revisions both of my own code and code pasted from online with people having the same issue, only to have Visual Studio throw no errors, run the code and have no luck, with it doing nothing but clearing the list box, and not showing matching results of any kind.
I understand this may be a repeat question but I am extremely confused, can't get anything to work and need some help regarding my issue.
Here is the current code (from online - not mine):
lbx_OFL_Results.Items.Clear()
Dim i As Integer
For i = 0 To lbx_OFL_Results.Items.Count - 1
If i > lbx_OFL_Results.Items.Count - 1 Then Exit For
If Not lbx_OFL_Results.Items(i).Contains(tbx_FindText.Text) Then
lbx_OFL_Results.Items.Remove(lbx_OFL_Results.Items(i))
i -= 1
End If
Next
The list box is called "lbx_OFL_Results"
The textbox is called "tbx_FindText"
I start by clearing the list box of all items (when the form loads, it fills the list box will all lines of the text file, so I need to clear it).
Form Load Event Code:
Dim lines1() As String = IO.File.ReadAllLines("C:\ProgramData\WPSECHELPER\.data\Outlook Folder Wizard\outlookfolders.txt")
lbx_OFL_Results.Items.AddRange(lines1)
For the rest of the code it seems to be doing some form of a 'sort search' then removing any excess results.
If anyone can suggest edits to my code, or new code then that would be sublime.
Thanks.
Thanks to #Jimi for the answer.
Code:
listbox.Items.Clear()
listbox.BeginUpdate()
For i as Integer = 0 To lines1().Length - 1
If lines1(i).Contains(searchbox.Text) Then
listbox.Items.Add(lines1(i))
End If
Next
listbox.EndUpdate()
I have another question which solves how to make this search non case-sensitive. It can be found here.

Outlook VBA - can view email Source Code?

In MS Outlook, I want to loop through each selected email, and for each email, view the source code and check if the source file (as in txt format) contains a certain string "XX". Since using view source code can display the email content into html format and I would like to trace some format which with issues in the text.
Currently, I am doing manually by opening the mail, right click > View source > Ctrl+F to find the string I am looking for.
Is there a view to use VBA to do the action of "view source" in the email?
Dim individualItem As Object
For Each individualItem In Application.ActiveExplorer.Selection
'View Source Code of the email
'Find "XX" in the email body content
If Instr(individualItem.body, "XX") = 1 Then
Msgbox ("Find string!")
End if
Next Message
Thanks.
You are almost right, I see two issues:
1.) There are two distinct properties Body (only text) and HTMLBody.
2.) Instr returns the position of the search token. It can be any positive number if the token is found.
So try:
If Instr(individualItem.HTMLBody, "XX") <> 0 Then
By "source" do you mean the MIME headers of the message? They are stored in the PR_TRANSPORT_MESSAGE_HEADERS property - take a look at the message with OutlookSpy (I am its author - click IMessage button). You can reads that property using MailItem.PropertyAccessor.GetProperty. The DASL name of the PR_TRANSPORT_MESSAGE_HEADERS property "http://schemas.microsoft.com/mapi/proptag/0x007D001F".
Note that full MIME source of a message is never stored by Outlook - MIME is not native Outlook format.

Nintex Mask Context item URL

I have created an email to send a notification when a list item has been modified.
The email should send a link to the item using Context Item URL. So far I have the email ending the URL , but is there anyway I can mask it so it just displays a hyperlink "View Here" rather than the whole url string ?
I have been trying for hours and have no Idea how to do this.
Thank you for your help
As usual as soon as I posted this I found the answer.
This turned out to be a peculiarity with SharePoint where it didn’t give any prompt or indications that you had to double click not just select an item.
1 Insert link
2 Place place you mouse in Address
3 Double Click the Context Item URL
4 Field Populates & enter the display name.

check if richtextbox contains textbox

I want to create a very simple login form is VB
All of the usernames are in a textfile on my webserver.
So first the program downloads that textfile with:
Dim wc As New WebClient()
Dim datawc.DownloadString("url.txt")
After that my program put the the text in a richbox with
RichTextBox1.Text = data
Then the programs checks if the text that is entered in the textbox is also in the richtextbox.
Now the problem is that if i fill in the textbox 1122, and in the richtextbox is 1133 that the program returns a correct response.
Sorry for my bad english
I just fixed it myself by using this condition
If data.Contains(TextBox1.Text) Then

HTTP get request in Visual Basic

I am totally new to VB as I have just started to learn it.
I have already created a user form with an input text box and a button. I want to be able to scan a barcode and implement it into this link: http://openean.kaufkauf.net/?ean=\[ean\]&cmd=query&queryid=200000000 replacing [ean] with the numbers from the barcode.
Afterwards make a HTTP GET request and having the result pop up in a message box. I do not know how to take the value of the text box, paste it into the link and make the request.
Assuming your text box is named TextBox1, try:
Dim request As String = String.Format("http://openean.kaufkauf.net/?ean={0}&cmd=query&queryid=200000000", TextBox1.Text)
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString(request)
MessageBox.Show(result)
Note that the above code will wait for the result from the server before allowing the user to interact with the application again, but it's enough to get you started.