Click here to Skip to main content
15,898,950 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello..

forget about my other questions, here is a new one.

my VCard file:

CSS
BEGIN:VCARD
VERSION:2.1
N:Voornaam;Naam
FN:Naam Voornaam
TEL;WORK;VOICE:0636345752
TEL;WORK;VOICE:0636345752
TEL;HOME;VOICE:0512540221
TEL;CELL;VOICE:0611299731
TEL;VOICE:0512540221
TEL;WORK;FAX:Fax
TEL;FAX:Mobiel
ADR;WORK;ENCODING=QUOTED-PRINTABLE:Sjoerd Veltmanstraat 15=0D=0A=
9203 NJ  Drachten
ADR;HOME:;;;;;;Nederland
ADR;POSTAL:;;;;;;Nederland
X-MS-OL-DEFAULT-POSTAL-ADDRESS:2
URL;HOME:Website
URL;WORK:www.mmportretstudio.nl
EMAIL;PREF;INTERNET:onnedejong@gmail.com
END:VCARD



I have 10 textboxes on my form.. one for "Naam", "Voornaam",.. etc etc.
Now i want to read the textboxes one by one.. and write the info to a textfile that i want to save as *.vcf.
I any one know how i can use the read and write methode???

thanks
Posted

You can simply use a StringBuilder to create the file content (from the textbox controls) and write them to a file. Have a look at the example at msdn:
http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx[^]
// Fill StringBuilder using AppendLine for all the items you want to add:
StringBuilder sb = new StringBuilder();
sb.AppendLine(txtName.ToString());
sb.AppendLine(txtPhone.ToString());
sb.AppendLine(txtEmail.ToString());

// write to file
using (StreamWriter outfile = new StreamWriter(@"test.vcf"))
{
    outfile.Write(sb.ToString());
}

Good luck!
 
Share this answer
 
v2
Comments
OdeJong 10-Apr-12 8:43am    
i dont know how to do it and msdn is to difficult for me..
the are not easy in explaining thing that's why i ask my question here..

i know that i can make 1 string with all the contents and then write them into a textfile so i can save as .vcf but i dont know how.
E.F. Nijboer 10-Apr-12 9:55am    
Added some code. But if msdn code examples are to hard I doubt if programming is for you. Just try something and see where it gets you. Be wild, and just try it! ;-)
VJ Reddy 10-Apr-12 11:07am    
+5. Good Answer. As OP said the text is in TextBoxes, then I think txtName.Text, etc. is more appropriate.
OdeJong 11-Apr-12 3:25am    
mwa, it's not to hard.. it's complicated because i'm from holland and i'm not so good @ English but thanks! I am one step closer now and it works fine! my code for now is:


'De volgende code zorgt ervoor dat het bestand wordt opgeslagen als V-Card (*.vcf).
Private Sub VCard()
Dim pad As String = _
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim resultaat As String
If MsgBox("Maak bestand", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then

resultaat = "BEGIN:VCard"
resultaat = resultaat & vbCrLf & "VERSION:2.1"
resultaat = resultaat & vbCrLf & "N:" & lstRelaties.SelectedItems(0).SubItems(2).Text
resultaat = resultaat & vbCrLf & "FN:" & lstRelaties.SelectedItems(0).SubItems(3).Text
resultaat = resultaat & vbCrLf & "TEL;WORK;VOICE:" & lstRelaties.SelectedItems(0).SubItems(7).Text
resultaat = resultaat & vbCrLf & "TEL;WORK;VOICE:" & lstRelaties.SelectedItems(0).SubItems(7).Text
resultaat = resultaat & vbCrLf & "TEL;HOME;VOICE:" & lstRelaties.SelectedItems(0).SubItems(8).Text
resultaat = resultaat & vbCrLf & "TEL;CELL;VOICE:" & lstRelaties.SelectedItems(0).SubItems(8).Text
resultaat = resultaat & vbCrLf & "TEL;VOICE:" & lstRelaties.SelectedItems(0).SubItems(9).Text
resultaat = resultaat & vbCrLf & "TEL;WORK;FAX:" & lstRelaties.SelectedItems(0).SubItems(10).Text
resultaat = resultaat & vbCrLf & "TEL;FAX:" & lstRelaties.SelectedItems(0).SubItems(10).Text
resultaat = resultaat & vbCrLf & "ADR;WORK;ENCODING=QUOTED-PRINTABLE:" & _
lstRelaties.SelectedItems(0).SubItems(4).Text & "=0D=0A=" & lstRelaties.SelectedItems(0).SubItems(5).Text
resultaat = resultaat & vbCrLf & "URL;HOME:" & lstRelaties.SelectedItems(0).SubItems(11).Text
resultaat = resultaat & vbCrLf & "URL;WORK:" & lstRelaties.SelectedItems(0).SubItems(11).Text
resultaat = resultaat & vbCrLf & "EMAIL;PREF;INTERNET:" & lstRelaties.SelectedItems(0).SubItems(10).Text
resultaat = resultaat & vbCrLf & "END:VCARD"

MsgBox(resultaat)






Using writer As StreamWriter = New StreamWriter(pad & "\Vcard.vcf")
writer.Write(resultaat.ToString())
End Using
End If



End Sub

The messagebox is to test what my app is doing by runtime
E.F. Nijboer 13-Apr-12 4:50am    
Luckely I'm from Holland myself ;-) and already assumed that reading the original question (ADR;HOME:;;;;;;Nederland). Would be a good idea to catch up on English though because its used very often in programming. You really get stuck quite easily because most method names are also in English.
Use the System.IO.File namespace. For example:
C#
System.IO.File.WriteAllLines()
 
Share this answer
 
I have solved this problem by myself with the last code I have posted on the form.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900