this kind of works, but you have to close the tab before exiting, or acad crashes
public class WebDoc
{
class HeadClient : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
var req = base.GetWebRequest(address);
if (req.Method == "GET")
req.Method = "HEAD";
return req;
}
}
public class Commands
{
private static bool PageExists(string url)
{
Uri uriResult;
if (!Uri.TryCreate(url, UriKind.Absolute, out uriResult) || uriResult.Scheme != Uri.UriSchemeHttp)
return false;
try
{
using (var client = new HeadClient())
{
client.DownloadString(url);
}
return true;
}
catch (WebException)
{
return false;
}
}
[CommandMethod("Doit")]
public static void OpenPage()
{
const string url = "http://www.theswamp.org/";
if (PageExists(url))
{
Application.DocumentWindowCollection.AddDocumentWindow("TheSwamp", new System.Uri(url));
}
else
{
var doc = Application.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
ed.WriteMessage("\nCould not load url: \"{0}\".", url);
}
}
}
}