How to add Url address?

Topics: User Forum
Jan 8, 2007 at 9:23 AM
I try to add a Url address in contact item and I get each time a UriFormatException.

Here's my code:

Uri url = new Uri(@"http://www.sample.com");
contact.Urls.Add(url, PropertyLabels.Personal);

What is wrong?


Jan 8, 2007 at 11:34 AM
I have found this:

UriBuilder UrlBld = new UriBuilder(@"http://www.abc.com");
contact.Urls.Add(UrlBld.Uri,PropertyLabels.Personal);

but I don't now if is it correct.
Coordinator
Jan 9, 2007 at 12:21 AM
This discussion has been copied to Work Item 7126. You may wish to continue further discussion there.
Coordinator
Jan 9, 2007 at 12:33 AM
The examples you posted should work. Can you give me the callstack where the exception is propagating from?

There is a bug where Uris put into the contact through the SetString methods may be retrieved incorrectly. I had the same bug in the Photos URL parsing code, which was causing your other issue before, but I missed fixing it in this case.

I just now checked in the fix for the above issue. Can you try the new sources and see if that maybe addresses your problem?
Jan 10, 2007 at 11:47 AM
Yes, it's right.

If url is "www.sample.com" or "http://www.sample.com", it's ok.

But, if url is "sample.com", I get a exception UriFormatException.

I think url given is checked before to add collection.

But when I read url from contact item, I get only
"www.sample.com" ( not "http://www.sample.com" ).

Coordinator
Jan 10, 2007 at 7:37 PM
Hmm... I'm not doing any extra validation of the URL before I store it in the contact. That's why I am using the URri class, so it will perform all the validation for me :)

I suspect that it's the Uri constructor that's actually throwing the exception, rather than the Contact code.