Marvin kakuru

Marvin kakuru

  • 1.4k
  • 359
  • 160.8k

view sms messages from sim card in modem

Feb 11 2016 12:15 PM
 
kindly below is the code i am trying to use but keep getting messagebox"There is no message in SIM" yet the sim card has got over 20 sms's
 
private void btnReadSMS_Click(object sender, EventArgs e)
{
try
{
//count SMS
int uCountSMS = objclsSMS.CountSMSmessages(this.port);
if (uCountSMS > 0)
{

#region Command
string strCommand = "AT+CMGR=\"ALL\"";

if (this.rbReadAll.Checked)
{
strCommand = "AT+CMGL=\"ALL\"";
}
else if (this.rbReadUnRead.Checked)
{
strCommand = "AT+CMGL=\"REC UNREAD\"";
}
else if (this.rbReadStoreSent.Checked)
{
strCommand = "AT+CMGL=\"STO SENT\"";
}
else if (this.rbReadStoreUnSent.Checked)
{
strCommand = "AT+CMGL=\"STO UNSENT\"";
}
#endregion

// If SMS exist then read SMS
#region Read SMS
//.............................................. Read all SMS ....................................................
objShortMessageCollection = objclsSMS.ReadSMS(this.port, strCommand);
foreach (ShortMessage msg in objShortMessageCollection)
{
textBox1.Text += msg.Message;

ListViewItem item = new ListViewItem(new string[] { msg.Index, msg.Sent, msg.Sender, msg.Message });
item.Tag = msg;
lvwMessages.Items.Add(item);



}
#endregion

}
else
{
lvwMessages.Clear();
//MessageBox.Show("There is no message in SIM");
this.statusBar1.Text = "There is no message in SIM";

}
}