C# – how to invoke IE to open a local html file

cinternet explorernet

I am using VSTS 2008 + C# + .Net 2.0. And I want to invoke IE to open an html file located under pages sub-folder of my current executable.

Since my program may run under Windows Vista, I want to invoke IE under administrative permissions (Run As Administrator).

Any code to make reference? I am especially interested in how to write portable code, which works on both Windows Vista and Windows XP (I think Windows XP does not have function like Run As Administrator)

EDIT 1:

I am using the following code, but there is no UAC (User Access Control) prompt message box opened up to let me select Continue to run with Administrator. Any ideas what is wrong?

    ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
    startInfo.Verb = "RunAs";
    startInfo.Arguments = @"C:\test\default.html";
    Process.Start(startInfo);

thanks in advance,
Geroge

Best Answer

For working with relative paths, give a look to the GetFullPath method.

string fullPath = Path.Combine(Path.GetFullPath(@".\dir\dir2"), "file.html");
System.Diagnostics.Process.Start("iexplore.exe", fullPath);