Outlook

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Outlook

 
0
  #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...


  1.  
  2. Outlook._Application olApp = new Outlook.ApplicationClass();
  3. Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
  4. Outlook.MAPIFolder oContacts = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
  5. Outlook.Items oItems = oContacts.Items;
  6. for (int i = 1; i <= oItems.Count; i++)
  7. {
  8. Outlook._ContactItem oContact = (Outlook._ContactItem)oItems.Item(i);
  9. list.Items.Add(oContact.FullName);
  10.  
  11.  
  12. oContact.SaveAs("C:\\apps\\" + list.SelectedItem,null);//error here
  13. oContact = null;
  14. }

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
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 55
Reputation: r0ckbaer is an unknown quantity at this point 
Solved Threads: 6
r0ckbaer r0ckbaer is offline Offline
Junior Poster in Training

Re: Outlook

 
0
  #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 Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Outlook

 
1
  #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 Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Outlook

 
0
  #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


  1. Outlook._Application olApp = new Outlook.ApplicationClass();
  2. Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
  3. Outlook.MAPIFolder oContacts = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
  4. Outlook.Items oItems = oContacts.Items;
  5. for (int i = 1; i <= oItems.Count; i++)
  6. {
  7. Outlook._ContactItem oContact = (Outlook._ContactItem)oItems.Item(i);
  8. list.Items.Add(oContact.FullName);
  9.  
  10.  
  11.  
  12. oContact.SaveAs(@"C:\" + oContact.FullName, Type.Missing);
  13. oContact = null;
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Outlook

 
0
  #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 Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Outlook

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

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

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 Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Outlook

 
0
  #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


  1. Outlook._Application olApp = new Outlook.ApplicationClass();
  2. Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
  3. Outlook.MAPIFolder oContacts = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
  4. Outlook.Items oItems = oContacts.Items;
  5. for (int i = 1; i <= oItems.Count; i++)
  6. {
  7. Outlook._ContactItem oContact = (Outlook._ContactItem)oItems.Item(i);
  8. list.Items.Add(oContact.FullName);
  9.  
  10.  
  11.  
  12. oContact.SaveAs(@"C:\" + oContact.FullName, Type.Missing);
  13. 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 Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: Outlook

 
0
  #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 Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Outlook

 
0
  #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


  1.  
  2. Outlook._Application olApp = new Outlook.ApplicationClass();
  3. Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
  4. Outlook.MAPIFolder oContacts = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
  5. Outlook.Items oItems = oContacts.Items;
  6. for (int i = 1; i <= oItems.Count; i++)
  7. {
  8. Outlook._ContactItem oContact = (Outlook._ContactItem)oItems.Item(i);
  9. list.Items.Add(oContact.FullName);
  10.  
  11.  
  12.  
  13. oContact.SaveAs(@"C:\" + oContact.FullName, Type.Missing);
  14. 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 Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: Outlook

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

  1.  
  2. contactlist.Columns.Add("Name", 100, HorizontalAlignment.Left);
  3. contactlist.Columns.Add("Job Title", 100, HorizontalAlignment.Left);
  4. contactlist.Columns.Add("Company", 100, HorizontalAlignment.Left);
  5. contactlist.Columns.Add("Email", 100, HorizontalAlignment.Left);
  6.  
  7. Outlook._Application olApp = new Outlook.ApplicationClass();
  8. Outlook._NameSpace olNs = olApp.GetNamespace("MAPI");
  9. Outlook.MAPIFolder oContacts = olNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
  10. Outlook.Items oItems = oContacts.Items;
  11. for (int i = 1; i <= oItems.Count; i++)
  12. {
  13. Outlook._ContactItem oContact = (Outlook._ContactItem)oItems.Item(i);
  14. ListViewItem itm = new ListViewItem();
  15. itm.Text = oContact.FullName;
  16. itm.SubItems.Add(oContact.JobTitle);
  17. itm.SubItems.Add(oContact.CompanyName);
  18. itm.SubItems.Add(oContact.Email1Address);
  19. contactlist.Items.Add(itm);
  20. oContact.SaveAs("C:\\Contacts\\" + oContact.FullName + ".vcf", Outlook.OlSaveAsType.olVCard);
  21. oContact = null;
  22. }
  23. }

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

  1. 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 Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC