Peter Kellner
Peter Kellner

Reputation: 15478

How To Properly Encode Tweets in Html (with c# hopefully)

I'm programmatically building up a tweet that end in #angularu which of course blocks the html from that point on. What is the proper way to encode a tweet so that it works and gives the full message in html

<a ng-href="http://twitter.com/home?status=Dan and John Bringing Their  https://angularu.com/ng/session/2015sf/dan-and-john-bringing-their-view-on-the-latest-in-angular Mon 11:00 AM Speakers: Wahlin @DanWahlin, Papa @John_Papa #angularu @AngularU " target="_blank" class="icon-twitter" href="http://twitter.com/home?status=Dan and John Bringing Their  https://angularu.com/ng/session/2015sf/dan-and-john-bringing-their-view-on-the-latest-in-angular Mon 11:00 AM Speakers: Wahlin @DanWahlin, Papa @John_Papa #angularu @AngularU "></a>

Upvotes: 1

Views: 63

Answers (1)

vcsjones
vcsjones

Reputation: 141628

You want to do a HttpUtility.UrlEncode:

Your link will render something like this:

<a href="http://twitter.com/home?status=Dan+and+John+blah%23angularu">Tweet</a>

For example, using the UriBuilder:

var builder = new UriBuilder(Uri.UriSchemeHttp, "twitter.com", 80, "/home");
builder.Query = "status=" + HttpUtility.UrlEncode("Dan and John are attending #angularU");
var uri = builder.ToString();

Upvotes: 1

Related Questions