RSS Forums RSS
Please support our C# advertiser: Programming Forums
Views: 5090 | Replies: 9 | Solved
Reply
Join Date: Jul 2005
Location: FL.
Posts: 1,536
Reputation: tayspen is on a distinguished road 
Rep Power: 7
Solved Threads: 98
Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Outlook

  #1  
Oct 22nd, 2005
Does any body know how to save your contacts in outlook to the harddrive. i no how to list them. but then i tried the save as methosd.

oContact.SaveAs("C:\contacts\" + list.selectedItem + ".vcf", null);


and that doesnt work. Any ideas?


my code...


 Outlook._Application olApp = new Outlook.ApplicationClass();
            Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
            Outlook.MAPIFolder oContacts = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
            Outlook.Items oItems = oContacts.Items;
            for (int i = 1; i <= oItems.Count; i++)
            {
                Outlook._ContactItem oContact = (Outlook._ContactItem)oItems.Item(i);
                list.Items.Add(oContact.FullName);
            
             
                oContact.SaveAs("C:\\apps\\" + list.SelectedItem,null);//error here
                oContact = null;
            }


EDIT:


here is the error



Can't write to file: C:\Apps\. Right-click the folder that contains the file you want to write to, and then click Properties on the shortcut menu to check your permissions for the folder.


yea i have permisstion i am admin and all....it gives that eroor no matter where i write
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2003
Posts: 55
Reputation: r0ckbaer is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 6
r0ckbaer r0ckbaer is offline Offline
Junior Poster in Training

Re: Outlook

  #2  
Oct 31st, 2005
Hello, you should check out the value of list.SelectedItem in the debugger (yes, that simple ), and see what it contains (i think i already told you that way to proceed in another thread )
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 204
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Outlook

  #3  
Nov 1st, 2005
are you trying to create a file that outlook can read? or is this copying the contacts for a different use?
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 204
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Outlook

  #4  
Nov 1st, 2005
well if you havent figured it out yet its because you are trying to use a selection in list before a selection can even be made.
in order to use the selection you need to click on it.

i fixed your code to make iit work, which adds the contact to the listbox and saves it using the current contact name, which is what the code should have done.

although. if there was a selection in the list i think it would recreate the same file during each loop, which could be a nother cause for a error, because the selection wont change just because you are adding and item

oh one more thing, dont expect to learn how things work if you just copy and paste off websites, and modifying it slightly. i googled this and found it on m$'s site lol


			Outlook._Application olApp = new Outlook.ApplicationClass();
			Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
			Outlook.MAPIFolder oContacts = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
			Outlook.Items oItems = oContacts.Items;
			for (int i = 1; i <= oItems.Count; i++)
			{
				Outlook._ContactItem oContact = (Outlook._ContactItem)oItems.Item(i);
				list.Items.Add(oContact.FullName);

            
             
				oContact.SaveAs(@"C:\" + oContact.FullName, Type.Missing);
				oContact = null;
Reply With Quote  
Join Date: Jul 2005
Location: FL.
Posts: 1,536
Reputation: tayspen is on a distinguished road 
Rep Power: 7
Solved Threads: 98
Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Outlook

  #5  
Nov 1st, 2005
Originally Posted by plazmo
are you trying to create a file that outlook can read? or is this copying the contacts for a different use?

Just copy the contacts for a different use. Like save on HD. But they are listed in a listbox, as you can see by the code. So i want it to save all the ones in the listbox. Any ideas on how to do this?

-T
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 204
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Outlook

  #6  
Nov 1st, 2005
i dont know why i am giving you such simple code but here

			for(int i = 0; i <= listBox1.Items.Count -1; i++)
			{
				SaveThis = listBox1.Items[i];
			}

it could also use foreach but i wasnt sure what type each item was(maybe string or item something)

"SaveThis" could be either a method to append a file or and object that stores the data to be saved
Reply With Quote  
Join Date: Jul 2005
Location: FL.
Posts: 1,536
Reputation: tayspen is on a distinguished road 
Rep Power: 7
Solved Threads: 98
Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Outlook

  #7  
Nov 1st, 2005
Originally Posted by plazmo
well if you havent figured it out yet its because you are trying to use a selection in list before a selection can even be made.
in order to use the selection you need to click on it.

i fixed your code to make iit work, which adds the contact to the listbox and saves it using the current contact name, which is what the code should have done.

although. if there was a selection in the list i think it would recreate the same file during each loop, which could be a nother cause for a error, because the selection wont change just because you are adding and item

oh one more thing, dont expect to learn how things work if you just copy and paste off websites, and modifying it slightly. i googled this and found it on m$'s site lol


			Outlook._Application olApp = new Outlook.ApplicationClass();
			Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
			Outlook.MAPIFolder oContacts = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
			Outlook.Items oItems = oContacts.Items;
			for (int i = 1; i <= oItems.Count; i++)
			{
				Outlook._ContactItem oContact = (Outlook._ContactItem)oItems.Item(i);
				list.Items.Add(oContact.FullName);

            
             
				oContact.SaveAs(@"C:\" + oContact.FullName, Type.Missing);
				oContact = null;

yea, but i didnt get if from MS. i got a a little help and modified it greatly ( i didnt post ALL of it thats just the listing part...). I had aleady tried somthing silmiliar to you SaveAs Method And it didnt work. And that didnt work either. And i do learn from it. I guess we all learn differently.

Thanks.

-T
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 204
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Outlook

  #8  
Nov 1st, 2005
if my code didnt work, then you prly have access errors, because this worded perfectly for me.

oh well that code was originally from ms site. anyways what formay are you saving it in?
Reply With Quote  
Join Date: Jul 2005
Location: FL.
Posts: 1,536
Reputation: tayspen is on a distinguished road 
Rep Power: 7
Solved Threads: 98
Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Outlook

  #9  
Nov 2nd, 2005
Originally Posted by tayspen
yea, but i didnt get if from MS. i got a a little help and modified it greatly ( i didnt post ALL of it thats just the listing part...). I had aleady tried somthing silmiliar to you SaveAs Method And it didnt work. And that didnt work either. And i do learn from it. I guess we all learn differently.

Thanks.

-T


I just directly used your code


Outlook._Application olApp = new Outlook.ApplicationClass();
			Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
			Outlook.MAPIFolder oContacts = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
			Outlook.Items oItems = oContacts.Items;
			for (int i = 1; i <= oItems.Count; i++)
			{
				Outlook._ContactItem oContact = (Outlook._ContactItem)oItems.Item(i);
				list.Items.Add(oContact.FullName);

            
             
				oContact.SaveAs(@"C:\" + oContact.FullName, Type.Missing);
				oContact = null;


it it says operation failed. I use this code on load method. I wasnt aware that you could specifya format. i must have overlooked that :rolleyes:

Thanks.

T
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote  
Join Date: Jul 2005
Location: FL.
Posts: 1,536
Reputation: tayspen is on a distinguished road 
Rep Power: 7
Solved Threads: 98
Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Outlook

  #10  
Nov 25th, 2005
Ok, so i figured this out quite a while ago....But forgot to post solution. Well here it is.

            contactlist.Columns.Add("Name", 100, HorizontalAlignment.Left);
            contactlist.Columns.Add("Job Title", 100, HorizontalAlignment.Left);
            contactlist.Columns.Add("Company", 100, HorizontalAlignment.Left);
            contactlist.Columns.Add("Email", 100, HorizontalAlignment.Left);

            Outlook._Application olApp = new Outlook.ApplicationClass();
            Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
            Outlook.MAPIFolder oContacts = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
            Outlook.Items oItems = oContacts.Items;
            for (int i = 1; i <= oItems.Count; i++)
            {
                Outlook._ContactItem oContact = (Outlook._ContactItem)oItems.Item(i);
                ListViewItem itm = new ListViewItem();
                itm.Text = oContact.FullName;
                itm.SubItems.Add(oContact.JobTitle);
                itm.SubItems.Add(oContact.CompanyName);
                itm.SubItems.Add(oContact.Email1Address);
                contactlist.Items.Add(itm);
                oContact.SaveAs("C:\\Contacts\\" + oContact.FullName + ".vcf", Outlook.OlSaveAsType.olVCard);
                oContact = null;
            }
        }
        

Thats lists all of out look contacts in a listview. Then it copies them to the C Drive. Note if you dont want it to save them leave out this

                oContact.SaveAs("C:\\Contacts\\" + oContact.FullName + ".vcf", Outlook.OlSaveAsType.olVCard);

Well there it is

-T
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:15 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC