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: .NET, C#, Code, Encoding, Nokia, SMS, Unicode, Windows
Related Posts
Comments
Jul 24, 2008 2:23 AM
Nokia PC suite can only be used to export messages...
regards, Pieter Paul
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! :)
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.
@Faisal, thanks for the link.
Want to leave a comment?

Feb 28, 2008 1:09 AM