Decode or Convert .VMG files to .TXT (Using C#)

See update below.

I used to have a Nokia phone, and backed up SMS messages using Nokia's PC Suite software. However, the messages were saved as .vmg files, which were encoded in unicode. Here's an example of how to decode a single .vmg file to a text file using C#. Converting the .vmg files to simple text files makes it a lot more convenient to read the messages later on. Of course, this isn't the only way to decode the files, and can be implemented with other languages.

 1 private void DecodeVMG()
2 {
3 FileInfo finfo = new FileInfo("SMSmessage.vmg");
4 FileStream stream = new FileStream(finfo.FullName,
5 FileMode.Open, FileAccess.Read);
6 BinaryReader br = new BinaryReader(stream);
7 byte[] data = br.ReadBytes((int)finfo.Length);
8 string decodedstring =
9 Encoding.Unicode.GetString(data).Trim();
10 using (StreamWriter writer
11 = new StreamWriter("DecodedMessage.txt"))
12 {
13 writer.WriteLine(decodedstring);
14 }
15 br.Close();
16 stream.Close();
17 }

Below is a sample output.

BEGIN:VMSG
VERSION:1.1
X-IRMC-STATUS:READ
X-IRMC-BOX:INBOX
X-NOK-DT:20070903T175600Z
X-MESSAGE-TYPE:DELIVER
BEGIN:VCARD
VERSION:3.0
N:
TEL:+19090000000
END:VCARD
BEGIN:VENV
BEGIN:VBODY
Date:03.09.2007 17:56:00
This is a test Message!
END:VBODY
END:VENV
END:VMSG

UPDATE (June 28, 2008): I noticed a large number of visits for this page, and I’m wondering if anyone will be interested if I created a simple program to do this conversion. I’ll be glad to hear your thoughts. Just leave a comment. Thanks!


Tags: , , , , , , ,

Bookmark and Share

Comments

umar
Feb 28, 2008 1:09 AM
umar i need your help
Pieter Paul
Jul 24, 2008 2:23 AM
Pieter Paul That would be great! that is if the program can also do same thing the other way around. Convert TXT, XML or CSV files to .VMG.
Nokia PC suite can only be used to export messages...

regards, Pieter Paul
Blazer
Aug 2, 2008 3:44 PM
Blazer Hi!
You actually made my day (or night which is more correct), I didn't know that the .vmg files actually were encoded in unicode and only a conversion would suffice. However I haven't used C# before, my experience is with c, c++, php, js, and the like, so as I would like to use the conversion bit in a more modified way to suit my needs, and also see it as a good way to learn some C#. I was wondering if its only standard C# library functions you have used and which that is, also if some external ones are used, where I can find them?

Anyways good job with the conversioun routine! :)
Faisal
Aug 3, 2008 11:33 AM
Faisal Thanks for the C# code.

It solved my problem in which I was stuck. I have translated the code in vb.net flavor. If you are interested in my story that why we take interest in this page as the author of this page ask then see it below the code.

Here is my code translated to vb.NET 2005 / 2008 with slight modifications from original.




Start of Code:
++++++++++++++++++++++++

Private Function decodeVMG(ByVal VMGFILEwithPath As String, ByVal NewFileNamewithPath As String) As String
Dim finfo As New IO.FileInfo(VMGFILEwithPath)
Dim Stream As New IO.FileStream(finfo.FullName, IO.FileMode.Open, IO.FileAccess.Read)
Dim br As New IO.BinaryReader(Stream)
Dim data() As Byte
data = br.ReadBytes(finfo.Length)
Dim decodestring As String = System.Text.Encoding.Unicode.GetString(data).Trim
My.Computer.FileSystem.WriteAllText(NewFileNamewithPath, decodestring, True)
br.Close()
Stream.Close()

Return decodestring
End Function

++++++++++
End of code.

Just copy & paste above code. It will work.


I am developing a program to read incoming sms from my nokia N91.

Why I visited this Page:
----------------------------
Problem with N91 is that there is no support to read sms neither by AT command, nor by Nokia SDK 3.0.

I was successful in reading sms from inbox & copying them in my C: drive using VB.NET the problem was that I was unable to open vmg file in textbox although the same vmg file can be opened in notepad.
Above help guide of C# code solved my problem.
Carlo
Aug 19, 2008 2:41 AM
Carlo It's great that this is being used somewhere. The program will have to wait. If it ever materializes, it will probably be a simple, one-way VMG to text converter.

@Faisal, thanks for the link.
Fabio Xodo
Oct 25, 2008 1:47 AM
Fabio Xodo Thanks to this, I developed a little program to convert all vmg file in a folder to TXT file in another.

You find the VS2008 project here:
http://www.senseiclassroom.net/lesson.asp?id=131

Of course the function found here have your credits ;)

Bye
Carlo
Oct 26, 2008 6:38 PM
Carlo @Fabio: Thanks! That's great.
Sapna
Mar 30, 2009 2:32 PM
Sapna Please create the utility and email me
Samuel James
May 6, 2009 10:30 PM
Samuel James I had created a utility to convert vmg file in to a single txt file. If any one needs exe please send a mail to me at samwillbe@gmail.com this utility is created using LabVIEW

This is free of cost
Bikkel
Jun 1, 2009 4:45 AM
Bikkel Hi Samuel

can you Please create the .exe utility
and sent it to me by email

Thanks! That would be great.

regards, Bikkel
ann
Jul 23, 2009 12:39 AM
ann can u tell me which link or website to download for change the vmg files to text files? cox i cant view back my vmg files..thanks!!!!

Want to leave a comment?