[源码、文档、分享] [原创]mobile联系人和短信操作 C#(转)
2011-05-09 11:43
501 查看
mobile联系人和短信操作
智能机的普及程度已经很高了 手机能为我们带来什么!!!!!!!!!! 复制内容到剪贴板
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.PocketOutlook;
using System.IO;
using MAPIdotnet;
namespace DeviceApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void ContactClear() // 清空电话簿
{
using (OutlookSession outlookSession = new OutlookSession())//创建OutlookSession 实例
{
outlookSession.Contacts.Items.Clear();//清空电话簿
}
}
private void button1_Click(object sender, EventArgs e)
{
if (DialogResult.Yes != MessageBox.Show("您确定要清空联系人吗?", "确认", MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2))
return;
ContactClear();
MessageBox.Show("成功执行!", "清空联系人");//通知用户,成功执行
}
void SMSBackup(string fileName) // 将短信息备份到指定文件
{
try
{
File.Delete(fileName);//删除文件
}
catch
{
}
using (MAPI mapi = new MAPI())
{
IMAPIMsgStore[] messageStores = mapi.MessageStores;
foreach (IMAPIMsgStore store in messageStores)
{
IMAPIFolderID inboxid = store.ReceiveFolder;//"收件箱"文件夹ID
IMAPIFolder inbox = store.OpenFolder(inboxid);//打开收件箱。其他文件夹也可使用类似方式打开
IMAPIMessage[] messages = inbox.GetNextMessages((int)inbox.NumSubItems);
using (StreamWriter sw = File.AppendText(fileName))//打开文件
{
foreach (IMAPIMessage msg in messages)//轮询SMS
{
sw.WriteLine("{0}:{1}", msg.Sender.FullAddress, msg.Subject);//将发件人,信息内容存入文件。这里仅保存发件人,信息内容。更多内容可自行添加
}
sw.Flush();
sw.Close();
}
}
}
}
private void button2_Click(object sender, EventArgs e)
{
if (DialogResult.OK == saveFileDialog1.ShowDialog())//用户确认选择了一个文件
{
string fileName = saveFileDialog1.FileName;//获取用户所选择的文件名
SMSBackup(saveFileDialog1.FileName);//将短信息备份到指定文件
MessageBox.Show("成功执行!", "备份短信息");//通知用户,成功执行
}
}
void SMSClear()// 清空短信息
{
using (MAPI mapi = new MAPI())
{
IMAPIMsgStore[] messageStores = mapi.MessageStores;
foreach (IMAPIMsgStore store in messageStores)
{
IMAPIFolderID inboxid = store.ReceiveFolder;//"收件箱"文件夹ID
IMAPIFolder inbox = store.OpenFolder(inboxid);//打开收件箱。其他文件夹也可使用类似方式打开
inbox.EmptyFolder();
//IMAPIMessage[] messages = inbox.GetNextMessages((int)inbox.NumSubItems);
//foreach (IMAPIMessage msg in messages)//轮询SMS
//{
// inbox.DeleteMessage(msg.MessageID);//删除SMS
//}
}
}
}
private void button3_Click(object sender, EventArgs e)
{
if (DialogResult.Yes != MessageBox.Show("您确定要清空短信息吗?", "确认", MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2))
return;
SMSClear();
MessageBox.Show("成功执行!", "清空短信息");//通知用户,成功执行
}
void ContactBackup(string fileName) // 将通讯簿备份到指定文件
{
try
{
File.Delete(fileName);//删除文件
}
catch
{
}
using (OutlookSession s = new OutlookSession())//创建OutlookSession实例
{
using (StreamWriter sw = File.AppendText(fileName))//打开文件
{
foreach (Contact c in s.Contacts.Items)//轮询通讯簿
{
sw.WriteLine("{0}:{1}", c.FileAs, c.MobileTelephoneNumber);//将姓名,手机号存入附件文件。这里仅保存姓名,手机号。更多内容可自行添加
}
sw.Flush();
sw.Close();
}
}
}
private void button4_Click(object sender, EventArgs e)
{
if (DialogResult.OK == saveFileDialog1.ShowDialog())//用户确认选择了一个文件
{
string fileName = saveFileDialog1.FileName;//获取用户所选择的文件名
ContactBackup(saveFileDialog1.FileName);//将通讯簿备份到指定文件
MessageBox.Show("成功执行!", "备份联系人");//通知用户,成功执行
}
}
}
}
智能机的普及程度已经很高了 手机能为我们带来什么!!!!!!!!!! 复制内容到剪贴板
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.PocketOutlook;
using System.IO;
using MAPIdotnet;
namespace DeviceApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
void ContactClear() // 清空电话簿
{
using (OutlookSession outlookSession = new OutlookSession())//创建OutlookSession 实例
{
outlookSession.Contacts.Items.Clear();//清空电话簿
}
}
private void button1_Click(object sender, EventArgs e)
{
if (DialogResult.Yes != MessageBox.Show("您确定要清空联系人吗?", "确认", MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2))
return;
ContactClear();
MessageBox.Show("成功执行!", "清空联系人");//通知用户,成功执行
}
void SMSBackup(string fileName) // 将短信息备份到指定文件
{
try
{
File.Delete(fileName);//删除文件
}
catch
{
}
using (MAPI mapi = new MAPI())
{
IMAPIMsgStore[] messageStores = mapi.MessageStores;
foreach (IMAPIMsgStore store in messageStores)
{
IMAPIFolderID inboxid = store.ReceiveFolder;//"收件箱"文件夹ID
IMAPIFolder inbox = store.OpenFolder(inboxid);//打开收件箱。其他文件夹也可使用类似方式打开
IMAPIMessage[] messages = inbox.GetNextMessages((int)inbox.NumSubItems);
using (StreamWriter sw = File.AppendText(fileName))//打开文件
{
foreach (IMAPIMessage msg in messages)//轮询SMS
{
sw.WriteLine("{0}:{1}", msg.Sender.FullAddress, msg.Subject);//将发件人,信息内容存入文件。这里仅保存发件人,信息内容。更多内容可自行添加
}
sw.Flush();
sw.Close();
}
}
}
}
private void button2_Click(object sender, EventArgs e)
{
if (DialogResult.OK == saveFileDialog1.ShowDialog())//用户确认选择了一个文件
{
string fileName = saveFileDialog1.FileName;//获取用户所选择的文件名
SMSBackup(saveFileDialog1.FileName);//将短信息备份到指定文件
MessageBox.Show("成功执行!", "备份短信息");//通知用户,成功执行
}
}
void SMSClear()// 清空短信息
{
using (MAPI mapi = new MAPI())
{
IMAPIMsgStore[] messageStores = mapi.MessageStores;
foreach (IMAPIMsgStore store in messageStores)
{
IMAPIFolderID inboxid = store.ReceiveFolder;//"收件箱"文件夹ID
IMAPIFolder inbox = store.OpenFolder(inboxid);//打开收件箱。其他文件夹也可使用类似方式打开
inbox.EmptyFolder();
//IMAPIMessage[] messages = inbox.GetNextMessages((int)inbox.NumSubItems);
//foreach (IMAPIMessage msg in messages)//轮询SMS
//{
// inbox.DeleteMessage(msg.MessageID);//删除SMS
//}
}
}
}
private void button3_Click(object sender, EventArgs e)
{
if (DialogResult.Yes != MessageBox.Show("您确定要清空短信息吗?", "确认", MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2))
return;
SMSClear();
MessageBox.Show("成功执行!", "清空短信息");//通知用户,成功执行
}
void ContactBackup(string fileName) // 将通讯簿备份到指定文件
{
try
{
File.Delete(fileName);//删除文件
}
catch
{
}
using (OutlookSession s = new OutlookSession())//创建OutlookSession实例
{
using (StreamWriter sw = File.AppendText(fileName))//打开文件
{
foreach (Contact c in s.Contacts.Items)//轮询通讯簿
{
sw.WriteLine("{0}:{1}", c.FileAs, c.MobileTelephoneNumber);//将姓名,手机号存入附件文件。这里仅保存姓名,手机号。更多内容可自行添加
}
sw.Flush();
sw.Close();
}
}
}
private void button4_Click(object sender, EventArgs e)
{
if (DialogResult.OK == saveFileDialog1.ShowDialog())//用户确认选择了一个文件
{
string fileName = saveFileDialog1.FileName;//获取用户所选择的文件名
ContactBackup(saveFileDialog1.FileName);//将通讯簿备份到指定文件
MessageBox.Show("成功执行!", "备份联系人");//通知用户,成功执行
}
}
}
}
相关文章推荐
- 【商业版、提供全部源码】基于RBAC的C#ASP.NET支持多用户的通用权限管理系统高质量源码10月份销售20套【提供操作手册设计文档下载】
- C# 短信猫(SMS cat) 操作源码开发经验
- C# 串口操作系列(1) -- 入门篇,一个标准的,简陋的串口例子。 ——兔子党逍遥原创,转来分享学习
- 分享一个C#操作Word完整源码
- 分享:用C#写了一个新增用户就发送邮件和手机短信的SqlServer触发器(附源码)
- C# 短信猫(SMS cat) 操作源码开发经验
- 分享 原创的一个模拟鼠标键盘操作的 设置简单 示例可以模拟向QQ群,以及QQ群内成员发送信息。
- C#动态生成WORD文档并进行操作。
- C# 连接操作SqlServer的方法分享
- C#操作RTF文档
- 原创 c# 封装的带CheckBox的DataGridViewColumnHeaderCell 源码部分 实现DataGridView列头带CheckBox控件实现全选功能,支持列头带标题
- C# 操作word文档
- [原创][翻译整理]使用RAPI库操作移动设备——C#语言描述
- C#操作XML文档
- 操作XML文档遇到的XMLNS问题及解决方法 (C# 和 PHP)
- [c#源码分享]客户端程序通过TCP通信传送"小文件"到服务器
- [导入]C#优化字符串操作【月儿原创】
- [C#]QQ开放平台(QQ站外登录)_流程和源码示例[原创]
- C#+MYSQL数据库操作(附源码)
- C# 操作XML文档 使用XmlDocument类方法