用C#导出outlook里的联系人 ??

Master Sergeant 2009-11-03 04:47:02
怎样导出outlook里面的联系人信息
本地的 和服务器的
能不能提供下源代码
...全文
684 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
vssvss 2009-11-05
  • 打赏
  • 举报
回复
我前段时间做的一个关于OutLook的东西 发给你几个链接,很全面的。
http://blog.csdn.net/liugy1126/archive/2009/05/11/4167956.aspx
http://msdn.microsoft.com/en-us/library/cc513843.aspx
http://msdn.microsoft.com/zh-cn/library/ms778202.aspx
http://www.cnblogs.com/iCeSnaker/articles/43101.html
http://msdn.microsoft.com/zh-cn/library/aa289167(VS.71).aspx
http://www.codeguru.cn/windows/Microsoft-Outlook-Ojbect/overview.htm
http://www.cnblogs.com/zyk/archive/2004/11/02/59707.html
vssvss 2009-11-04
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 herojams 的回复:]
取服务器数据需要涉及到Exchange知识,在此提供本地获取
以前做的Outlook插件.
C# codeusing System;using System.Data;using Outlook= Microsoft.Office.Interop.Outlook;using System.Collections.Generic;using System.Text;using System.Windows.Forms;namespace OutlookAddin1
{publicstaticclass OutlookTool
{publicstaticvoid CreateTask(DataRow row)
{// Create a new task item. Outlook.MAPIFolder tasksFolder= Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
Outlook.TaskItem item= (Outlook.TaskItem)tasksFolder.Items.Add(Outlook.OlItemType.olTaskItem);
item.Subject= row["Subject"].ToString();
item.Owner= row["Owner"].ToString();
item.PercentComplete=int.Parse(row["PercentComplete"].ToString());
item.Status= (Outlook.OlTaskStatus)int.Parse(row["Status"].ToString());

item.Save();
}publicstaticvoid CreateContact(DataRow row)
{// Create a new contact item. Outlook.MAPIFolder contactFolder= Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.ContactItem item= (Outlook.ContactItem)contactFolder.Items.Add(Outlook.OlItemType.olContactItem);
item.FirstName= row["firstName"].ToString();
item.LastName= row["lastName"].ToString();
item.Department= row["department"].ToString();
item.JobTitle= row["jobTitle"].ToString();
item.Email1Address= row["email"].ToString();

item.Save();
}publicstaticstring GetContactsXML()
{// Get all contacts Outlook.MAPIFolder contactsFolder= Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
StringBuilder xml=new StringBuilder("<contacts>",100);for(int i=1;i<=contactsFolder.Items.Count;i++)
{
Outlook.ContactItem item= contactsFolder.Items[i]as Outlook.ContactItem;
xml.Append("<contact>");
xml.Append("<firstName>"+ item.Subject+"</firstName>");
xml.Append("<lastName>"+ item.LastName+"</lastName>");
xml.Append("<department>"+ item.Department+"</department>");
xml.Append("<jobTitle>"+ item.JobTitle+"</jobTitle>");
xml.Append("<email>"+ item.Email1Address+"</email>");
xml.Append("</contact>");if (i>50)break;
}
xml.Append("</contacts>");return xml.ToString();

}publicstaticstring GetTaskXML()
{// Get all tasks Outlook.MAPIFolder tasksFolder= Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
StringBuilder xml=new StringBuilder("<tasks>",100);foreach (Outlook.TaskItem itemin tasksFolder.Items)
{
xml.Append("<task>");
xml.Append("<subject>"+ item.Subject+"</subject>");
xml.Append("<owner>"+ item.Owner+"</owner>");
xml.Append("<percentComplete>"+ item.PercentComplete.ToString()+"</percentComplete>");
xml.Append("<status>"+ ((int)item.Status).ToString()+"</status>");
xml.Append("</task>");
}
xml.Append("</tasks>");return xml.ToString();
}publicstaticvoid CreateAppointmentInCalendar(DataRow row)
{// Create a new appointment item in calendar. Outlook.MAPIFolder tasksFolder= Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.AppointmentItem appointmentitem= (Outlook.AppointmentItem)tasksFolder.Items.Add(Outlook.OlItemType.olAppointmentItem);
appointmentitem.Subject= row["subject"].ToString();
appointmentitem.Body= row["body"].ToString();
appointmentitem.Start= DateTime.Parse(row["Start"].ToString());
appointmentitem.End= DateTime.Parse(row["End"].ToString());
appointmentitem.Save();
}publicstaticstring GetAppointmentsXML()
{
Outlook.MAPIFolder appointmentFolder= Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
StringBuilder xml=new StringBuilder("<appointments>",100);foreach (Outlook.AppointmentItem itemin appointmentFolder.Items)
{
xml.Append("<appointment>");
xml.Append("<subject>"+ item.Subject+"</subject>");
xml.Append("<body>"+ item.Body+"</body>");
xml.Append("<start>"+ item.Start.ToString()+"</start>");
xml.Append("<end>"+ item.End.ToString()+"</end>");
xml.Append("</appointment>");
}
xml.Append("</appointments>");return xml.ToString();
}privatestatic ListView GetListView(string title,string[] cols)
{
ListView listView=new ListView();
listView.Dock= DockStyle.Fill;
listView.View= View.Details;foreach (string colin cols)
{
listView.Columns.Add(col);
}return listView;
}


}
}
[/Quote]
这个就可以了 也没必要这么麻烦 你自己改下就可以
_see_you_again_ 2009-11-03
  • 打赏
  • 举报
回复
取服务器数据需要涉及到Exchange知识,在此提供本地获取
以前做的Outlook插件.

using System;
using System.Data;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace OutlookAddin1
{
public static class OutlookTool
{

public static void CreateTask(DataRow row)
{
// Create a new task item.
Outlook.MAPIFolder tasksFolder = Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
Outlook.TaskItem item = (Outlook.TaskItem)tasksFolder.Items.Add(Outlook.OlItemType.olTaskItem);
item.Subject = row["Subject"].ToString();
item.Owner = row["Owner"].ToString();
item.PercentComplete = int.Parse(row["PercentComplete"].ToString());
item.Status = (Outlook.OlTaskStatus)int.Parse(row["Status"].ToString());

item.Save();
}
public static void CreateContact(DataRow row)
{
// Create a new contact item.
Outlook.MAPIFolder contactFolder = Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.ContactItem item = (Outlook.ContactItem)contactFolder.Items.Add(Outlook.OlItemType.olContactItem);
item.FirstName = row["firstName"].ToString();
item.LastName = row["lastName"].ToString();
item.Department = row["department"].ToString();
item.JobTitle = row["jobTitle"].ToString();
item.Email1Address = row["email"].ToString();

item.Save();
}
public static string GetContactsXML()
{
// Get all contacts
Outlook.MAPIFolder contactsFolder = Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
StringBuilder xml = new StringBuilder("<contacts>", 100);
for(int i=1;i<=contactsFolder.Items.Count;i++)
{
Outlook.ContactItem item = contactsFolder.Items[i] as Outlook.ContactItem;
xml.Append("<contact>");
xml.Append("<firstName>" + item.Subject + "</firstName>");
xml.Append("<lastName>" + item.LastName + "</lastName>");
xml.Append("<department>" + item.Department + "</department>");
xml.Append("<jobTitle>" + item.JobTitle + "</jobTitle>");
xml.Append("<email>" + item.Email1Address + "</email>");
xml.Append("</contact>");
if (i > 50)
break;
}
xml.Append("</contacts>");
return xml.ToString();

}
public static string GetTaskXML()
{
// Get all tasks
Outlook.MAPIFolder tasksFolder = Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderTasks);
StringBuilder xml = new StringBuilder("<tasks>", 100);
foreach (Outlook.TaskItem item in tasksFolder.Items)
{
xml.Append("<task>");
xml.Append("<subject>" + item.Subject + "</subject>");
xml.Append("<owner>" + item.Owner + "</owner>");
xml.Append("<percentComplete>" + item.PercentComplete.ToString() + "</percentComplete>");
xml.Append("<status>" + ((int)item.Status).ToString() + "</status>");
xml.Append("</task>");
}
xml.Append("</tasks>");
return xml.ToString();
}
public static void CreateAppointmentInCalendar(DataRow row)
{
// Create a new appointment item in calendar.
Outlook.MAPIFolder tasksFolder = Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.AppointmentItem appointmentitem = (Outlook.AppointmentItem)tasksFolder.Items.Add(Outlook.OlItemType.olAppointmentItem);
appointmentitem.Subject = row["subject"].ToString();
appointmentitem.Body = row["body"].ToString();
appointmentitem.Start = DateTime.Parse(row["Start"].ToString());
appointmentitem.End = DateTime.Parse(row["End"].ToString());
appointmentitem.Save();
}
public static string GetAppointmentsXML()
{
Outlook.MAPIFolder appointmentFolder = Globals.ThisApplication.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
StringBuilder xml =new StringBuilder( "<appointments>",100);
foreach (Outlook.AppointmentItem item in appointmentFolder.Items)
{
xml.Append("<appointment>");
xml.Append("<subject>" + item.Subject + "</subject>");
xml.Append("<body>" + item.Body + "</body>");
xml.Append("<start>" + item.Start.ToString() + "</start>");
xml.Append("<end>" + item.End.ToString() + "</end>");
xml.Append("</appointment>");
}
xml.Append("</appointments>");
return xml.ToString();
}
private static ListView GetListView(string title, string[] cols)
{
ListView listView = new ListView();
listView.Dock = DockStyle.Fill;
listView.View = View.Details;
foreach (string col in cols)
{
listView.Columns.Add(col);
}
return listView;
}


}
}

你妹的特盗不 2009-11-03
  • 打赏
  • 举报
回复
up

study

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧