Microsoft Most Valuable Professional

Chris Pietschmann

An MVP From Wisconsin

C# .NET: Convert System.Drawing.Color to HTML color

Here is a small example of how to convert a System.Drawing.Color to the HTML color format (Hex value or HTML color name value) and back.

System.Drawing.Color c = System.Drawing.ColorTranslator.FromHtml("#F5F7F8");
String strHtmlColor = System.Drawing.ColorTranslator.ToHtml(c);

 

Currently rated 4.4 by 13 people

  • Currently 4.384614/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: General
Posted by crpietschmann on Thursday, June 29, 2006 2:48 PM
Permalink | Comments (5) | Post RSSRSS comment feed


ASP.NET 2.0: v0.02 of my Virtual Earth v3 Ajax Server Control

Update (11/7/2007): This control is now located here: http://codeplex.com/pietschsoftve3

I just uploaded a new release (v0.02) of my ASP.NET 2.0 Virtual Earth v3 Server Control. The download contains a Visual Studio 2005 solution that contains the source code for the server control dll and a sample website that uses the control. The only new feature in this release is full ViewState support. I do plan on adding many more features to this control as I get time to work on it. Enjoy!

Download PietschSoft.VE3 v0.02 Server Control

Info on the initial release (v0.01) of the control:
ASP.NET 2.0: Virtual Earth v3 Custom Control - PietschSoft.VE3 v0.01

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by crpietschmann on Sunday, June 25, 2006 11:52 PM
Permalink | Comments (2) | Post RSSRSS comment feed


ASP.NET Atlas is full of JavaScript goodness

I was looking through the JavaScript code for Atlas and I noticed there is some pretty neat stuff in there. It is really a very large enhancement to JavaScript.

One of the things I noticed is they are adding support for the XMLHttpRequest object if the browser doesn't natively support it. In the past I've traditionally just created a function named similarly to 'CreateXMLHttpRequestObject' and I make that function support multiple browsers. The technique that's used in Atlas is they are adding the 'window.XMLHttpRequest' object if it doesn't already exist. This allows for your AJAX code to support multiple browsers more easily by making it so you don't need to change your code to support Internet Explorer. And your code will still work in IE7 because IE7 natively supports the 'window.XMLHttpRequest' object. Very nice guys!

Below is the above mentioned chunk of JS code for your viewing pleasure:

//-----------------------------------------------------------------------
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------
// Atlas.js
// Atlas Framework.
//
if (!window.XMLHttpRequest) {
    window.XMLHttpRequest = function() {
        var progIDs = [ 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' ];
    
        for (var i = 0; i < progIDs.length; i++) {
            try {
                var xmlHttp = new ActiveXObject(progIDs[i]);
                return xmlHttp;
            }
            catch (ex) {
            }
        }
    
        return null;
    }
}

 

Remember the above code is technically copyrighted to Microsoft and is part of the Atlas Framework.

ASP.NET Atlas Framwork

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: General
Posted by crpietschmann on Wednesday, June 21, 2006 9:00 AM
Permalink | Comments (1) | Post RSSRSS comment feed


Scrape Geocodes from Google Maps w/ C#

I need to geocode some addresses once in a while and I notice if you view the source of the Google Maps page, the geocodes are right there. So instead of looking at the source of the page manually, I just created a little app that scrapes them from the page for me and places them into textboxes.

Below is a small code snippet I wrote that does just that. It's not perfect but it is simple and it just plain works.

string lat = "";
string lng = "";
string address = "1 Microsoft Way, Redmond WA";

try
{
System.Net.
WebClient client = new System.Net.WebClient();
string page = client.DownloadString("http://maps.google.com/maps?q=" + address);
int begin = page.IndexOf("markers: [");
string str = page.Substring(begin);
int end = str.IndexOf(",image:");
str = str.Substring(0, end);

//Parse out Latitude
lat = str.Substring(str.IndexOf(",lat: ") + 6);
lat = lat.Substring(0, lat.IndexOf(
",lng: "));
//Parse out Longitude
lng = str.Substring(str.IndexOf(",lng: ") + 6);
}
catch (Exception ex)
{
MessageBox.Show("An Error Occured Loading Geocode!\nCheck that a valid address has been entered.", "An Error Occured Loading Geocode!");
}
MessageBox.Show("Latitude:\n" + lat + "\n\nLongitude:\n" + lng);

 

I know I should have used Regular Expressions, but I don't know them very well and this was just quicker/easier to do. It took all of like 5 minutes.

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: General
Posted by crpietschmann on Tuesday, June 13, 2006 9:00 AM
Permalink | Comments (3) | Post RSSRSS comment feed

ASP.NET 2.0: Virtual Earth v3 Ajax Server Control - PietschSoft.VE3 v0.01

Here is v0.01 of my ASP.NET Virtual Earth v3 custom control. The zip file download contains the DLL code and a sample test website.

PietschSoft.VE3 v0.01 Features:

  • Display map on a page with server side parameters (latitude, longitude, zoom, map style, etc.)
  • Ability to attach JavaScript functions to the events raised by the JavaScript VEMap object from within server side code.
  • Ability to plot points on the map from with in server side code

I am modeling the objects in my library after the objects in the Virtual Earth v3 JavaScript API and I'm nameing the objects, methods and parameters as closely as possible to their Virtual Earth counterparts.

Remember this is my first release of this control, so it only implements the most basic features.

Download PietschSoft.VE3 Library

Update 10/22/2007: There is an all New ASP.NET AJAX Virtual Earth Mapping Server Control with much richer Ajax support that PietschSoft.VE located here: http://simplovation.com/Page/WebMapsVE.aspx

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by crpietschmann on Wednesday, June 07, 2006 10:38 PM
Permalink | Comments (6) | Post RSSRSS comment feed

ASP.NET 2.0: Place JavaScript inside the Page.Header

The Page.ClientScript object allows you to place JavaScript inside the Page, but it's limited in the fact that you cannot use it to place JavaScript inside the Head tags of the Page. But fortunately there is a way to do this.

Add a .js file include inside the page header:

[code:c#]
HtmlGenericControl Include = new HtmlGenericControl("script");
Include.Attributes.Add("type", "text/javascript");
Include.Attributes.Add("src", "http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js");
this.Page.Header.Controls.Add(Include);
[/code]

Add some JavaScript inside the page header:

[code:c#]
HtmlGenericControl Include2 = new HtmlGenericControl("script");
Include2.Attributes.Add("type", "text/javascript");
Include2.InnerHtml = "alert('JavaScript in Page Header');";
this.Page.Header.Controls.Add(Include2);
[/code]

It would be nice if there was a Page.Header.ClientScript object that you could use to place JavaScript within the header of the Page, but for now we'll just have to use the method stated above.

Currently rated 4.3 by 6 people

  • Currently 4.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:
Categories: General
Posted by crpietschmann on Saturday, June 03, 2006 12:38 AM
Permalink | Comments (9) | Post RSSRSS comment feed

JavaScript: Loop through all elements in a form

Since I've been doing alot of JavaScript programming lately, I figured I could start blogging some code snippets. Here is a JavaScript snippet that shows how to loop through all the elements in a form and retrieve their element type, name and values. I had to use this code to gather all form values so I could post them to the server using AJAX.

[code:html]
<html>
<head>
<script type="text/javascript">
function DisplayFormValues()
{
var str = '';
var elem = document.getElementById('frmMain').elements;
for(var i = 0; i < elem.length; i++)
{
str += "<b>Type:</b>" + elem[i].type + "&nbsp&nbsp";
str += "<b>Name:</b>" + elem[i].name + "&nbsp;&nbsp;";
str += "<b>Value:</b><i>" + elem[i].value + "</i>&nbsp;&nbsp;";
str += "<BR>";
}
document.getElementById('lblValues').innerHTML = str;
}
</script>
</head>
<body>
<form id="frmMain" name="frmMain">
<input type="hidden" name="ElemHidden" value="some hidden text" />
<input type="text" name="ElemText" value="some text" /><br />
<textarea name="ElemTextArea">Some text area text</textarea><br />
<br />
<input type="button" value="Test" onclick="DisplayFormValues();" />
</form>
<hr />
<div id="lblValues"></div>
</body>
</html>
[/code]

Currently rated 3.3 by 11 people

  • Currently 3.272726/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: General
Posted by crpietschmann on Thursday, June 01, 2006 9:02 AM
Permalink | Comments (4) | Post RSSRSS comment feed

About the author

I'm Chris Pietschmann, go to the About Me page to learn more about me.

Search

Sponsors

Web.Maps.VE - ASP.NET AJAX Virtual Earth Mapping Server Control

Recent comments

Disclaimer


This work is licensed under a Creative Commons Attribution 3.0 United States License, unless explicitly stated otherwise within the posted content.
© Copyright 2004 - 2008 Chris Pietschmann