Please support our C# advertiser: Programming Forums
Views: 5090 | Replies: 9 | Solved
![]() |
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...
EDIT:
here is the error
yea i have permisstion i am admin and all....it gives that eroor no matter where i write
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
Ewido
Tune up windows
Get detailed system information
My Fixes
Member - Alliance of Security Analysis Professionals - Since 2006
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
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;•
•
•
•
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
Ewido
Tune up windows
Get detailed system information
My Fixes
Member - Alliance of Security Analysis Professionals - Since 2006
i dont know why i am giving you such simple code but here
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
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
•
•
•
•
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
Ewido
Tune up windows
Get detailed system information
My Fixes
Member - Alliance of Security Analysis Professionals - Since 2006
•
•
•
•
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
Ewido
Tune up windows
Get detailed system information
My Fixes
Member - Alliance of Security Analysis Professionals - Since 2006
Ok, so i figured this out quite a while ago....But forgot to post solution. Well here it is.
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
Well there it is
-T
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
Ewido
Tune up windows
Get detailed system information
My Fixes
Member - Alliance of Security Analysis Professionals - Since 2006
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






), and see what it contains (i think i already told you that way to proceed in another thread
Linear Mode