943,865 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 7678
  • C# RSS
Oct 22nd, 2005
0

Outlook

Expand Post »
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...


C# Syntax (Toggle Plain Text)
  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


Quote ...

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
Similar Threads
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Oct 31st, 2005
0

Re: Outlook

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 )
Reputation Points: 13
Solved Threads: 6
Junior Poster in Training
r0ckbaer is offline Offline
55 posts
since Dec 2003
Nov 1st, 2005
1

Re: Outlook

are you trying to create a file that outlook can read? or is this copying the contacts for a different use?
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Nov 1st, 2005
0

Re: Outlook

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


C# Syntax (Toggle Plain Text)
  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;
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Nov 1st, 2005
0

Re: Outlook

Quote 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
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Nov 1st, 2005
0

Re: Outlook

i dont know why i am giving you such simple code but here

C# Syntax (Toggle Plain Text)
  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
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Nov 1st, 2005
0

Re: Outlook

Quote 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


C# Syntax (Toggle Plain Text)
  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
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Nov 1st, 2005
0

Re: Outlook

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?
Reputation Points: 23
Solved Threads: 16
Posting Whiz in Training
plazmo is offline Offline
206 posts
since Aug 2005
Nov 2nd, 2005
0

Re: Outlook

Quote 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


C# Syntax (Toggle Plain Text)
  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
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005
Nov 25th, 2005
0

Re: Outlook

Ok, so i figured this out quite a while ago....But forgot to post solution. Well here it is.

C# Syntax (Toggle Plain Text)
  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

C# Syntax (Toggle Plain Text)
  1. oContact.SaveAs("C:\\Contacts\\" + oContact.FullName + ".vcf", Outlook.OlSaveAsType.olVCard);

Well there it is

-T
Team Colleague
Reputation Points: 84
Solved Threads: 99
<Insert title here>
tayspen is offline Offline
1,542 posts
since Jul 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Where is System.Text.Encoding.EBCDIC?
Next Thread in C# Forum Timeline: Basic Question





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC