Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

Show raw Text Code from a URL with CodePaste.NET

On this page:

I introduced CodePaste.NET more than 2 years ago. In case you haven't checked it out it's a code-sharing site where you can post some code, assign a title and syntax scheme to it and then share it with others via a short URL. The idea is super simple and it's not the first time this has been done, but it's focused on Microsoft languages and caters to that crowd.

Show your own code from the Web

There's another feature that I tweeted about recently that's been there for some time, but is not used very much: CodePaste.NET has the ability to show raw text based code from a URL on the Web in syntax colored format for any of the formats provided. I use this all the time with code links to my Subversion repository which only displays code as plain text. Using CodePaste.NET allows me to show syntax colored versions of the same code.

For example I can go from this URL:



To a nicely colored source code view at this Url:


which looks like this:


Use the Form or access URLs directly

To get there navigate to the Web Code icon on the CodePaste.NET site and paste your original URL and select a language to display:


The form creates a link shown above which has two query string parameters:

  • url - The URL for the raw text on the Web
  • language -  The code language used for syntax highlighting

Note that parameters must be URL encoded to work especially the # in C# because otherwise the # will be interpreted by the browser as a hash tag to jump to in the target URL.

The URL must be Web accessible so that CodePaste can download it and then apply the syntax coloring. It doesn't work with localhost urls for example. The code returned must be returned in plain text - HTML based text doesn't work.

Hope some of you find this a useful feature. Enjoy…

Posted in .NET  

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024