Removing Phonebook Entry and Conditionally skipping Entry Add?

Aug 2, 2011 at 12:48 PM

I'm very new to coding, and I followed your youtube video exactly for creating a phonebook entry when clicking a button, and it works (this.RasPhoneBook1.Entries.Add(....


But when I try to write code to remove the entry, it doesn't appear to be working. Here's the code I have for the removal:



this.RasPhoneBook1.Entries.Remove("VPN Name");



Any ideas as to what I'm missing?


Also, can someone help guide me in the right direction for conditionally checking if a given entry exists then skip adding the phonebook entry?

Thank you very much.


Aug 2, 2011 at 7:35 PM

Well, your syntax for opening the phonebook is wrong... this.RasPhoneBook1.Open();

As for removing the entry, all you need to do is call Remove as you showed in your question. You just need to make sure you're opening the same phone book as where you put it, otherwise it may throw an exception because it's missing.

As for checking whether an entry already exists in the phone book, you can use the this.RasPhoneBook1.Entries.Contains("VPN Name"); method... it returns a boolean indicating whether the entry already exists in the phone book.

Aug 2, 2011 at 7:51 PM

I didn't have my VB in front of me, so how you have it is how I have it.

So then, will calling this.RasPhoneBook1.Open(); open the correct phone book across different sessions (I closed the program and re-opened it)? I'm using the same phone book (RasPhoneBook1) throughout my code. Is there something else I need to specify in opening the PhoneBook?

I'm a bit confused as to where this information is getting stored, as it doesn't seem to be storing it in the standard Pbk directory for my user.

Thanks again for the help.

Aug 2, 2011 at 9:41 PM

There are multiple phonebooks that are in use by Windows at any given time. As indicated in the documentation (which you might want to read for the objects you're using) depending on which overload of Open you call determines which phonebook on your hard drive is opened.

The "correct" phonebook is determined by your application requirements. Calling the same overload of Open will in open the same phone book as the previous call, assuming you haven't passed some strange path to the method in the Open(string) overload.

Aug 2, 2011 at 10:09 PM
Edited Aug 2, 2011 at 10:12 PM

I can't seem to get the Remove button to work. It doesn't give any errors when I click the Remove button, but it doesn't remove it, either.

So here's my code for the Add button:

        private void button2_click(object sender, EventArgs e)

            RasEntry entry = RasEntry.CreateVpnEntry("Test VPN", "myipaddresshere", RasVpnStrategy.PptpOnly, 
                RasDevice.GetDeviceByName("(PPTP)", RasDeviceType.Vpn, false));

For the Remove button:

        private void button5_Click(object sender, EventArgs e)

            this.rasPhoneBook1.Entries.Remove("Test VPN");
Aug 3, 2011 at 4:15 AM

Well, is your click event handler for button 5 being called?

With 1.2 you should have seen an exception being thrown if you called Open on the same RasPhoneBook instance twice.