Database den Outlook Contact Oluşturma

Sql serverdaki müşteri database’i iphone için bir contact list teşkil etmekte idi ama iphone outlooktan sync edebildiği için müşteri resimleri ile beraber db yi contact liste eklemem lazımdı .
bu sorunu bir form yardımı ile halletmiş bulunmaktayım

yeni bir c# projesi açalım ve bir form ekliyelim
1 adet progress bar
1 adet data grid
1 adet button


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

// office namespacelerini tanımlıyalım öncelikle
using Microsoft.Office.Interop.Outlook;
using Microsoft.Office.Core;

using Outlook = Microsoft.Office.Interop.Outlook;
using Marshal = Microsoft.Office.Interop.Outlook;
using System.IO;


namespace OutlookExporter
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
// ben dırek olarak vs ile gelen databinding den yararlandıgım ıcın db ye baglanmak ıcın bır class kullanmadan dırek olaya gırdım... sizde bir tane yaratın ve form loadda bunu fill ettirin 
tabi form uzerınden databinding olayını ayarlamanız lazım grıd için
            this.hastaTableAdapter.Fill(this.ivf4DataSet1.hasta);

        }


  
        private void button1_Click(object sender, EventArgs e)
        
        {

            MessageBox.Show("Export işlemi Toplam : " + dataGridView1.RowCount.ToString() + " Kayıt için yapılacaktır.\n İşlem Bilgisayarınızda Donmaya Neden olabilir \n Outlook Kişileriniz Silinecektir\n\n Lütfen Bekleyiniz ");
            


           
                     foreach (DataRow row in dt.Rows)
            {

                progressBar1.Value++;
                Outlook.ContactItem ci = (Outlook.ContactItem)outlookApp.CreateItem(OlItemType.olContactItem);



                ci.HomeAddress = "TC Kimlik  NO : " + row[0].ToString() + "\n \n Pno : " + row[2].ToString() + "\n \n Kayıt Tarihi : " + row[1].ToString();
                         ci.MobileTelephoneNumber = row[5].ToString();
                        ci.BusinessTelephoneNumber = row[6].ToString();
                        ci.HomeTelephoneNumber =  row[7].ToString();
                                    ci.LastName = row[4].ToString();

                    ci.FirstName = row[3].ToString();
                    ci.Email1Address = row[8].ToString();


                    string imagePath = "J:\\IphoneDev\\Jpg\\" + row[2].ToString() + ".jpg";

                    if (!File.Exists(imagePath))
                    {
                        imagePath = "c:\\error.png";
                    }


                    ci.AddPicture(imagePath);
                    ci.AddBusinessCardLogoPicture(imagePath);

                    ci.CustomerID = row[1].ToString();
                    ci.WebPage = "https://www.****.com/**.aspx?id=" + row[2].ToString();
                    ci.Save();
                    label1.Text = progressBar1.Value.ToString();

// Buraya dikkat benim db de 15680 ın uzerınde kayıt vardı  :)
                    System.Threading.Thread.Sleep(50);
                    System.GC.Collect();
         

            }
      




        }
      
    }
}

Ekran Görüntüleri

Leave a Reply