Opening a Webdocument in the default browser is a qeustion that have been answered a minnion times. But I have a twist to the question:
How can I in C# open or Refresh a html document in the default browser.
If I try some thing like this:
private Process ShowFile(string htmlFilename)
{
var myProcess = new Process();
try
{
// true is the default, but it is important not to set it to false
myProcess.StartInfo.UseShellExecute = true;
myProcess.StartInfo.FileName = htmlFilename;
myProcess.Start();
}
catch (Exception e)
{
}
return myProcess;
}
A new window is opened each time.
* EDIT *
I have tried this but the Browser doesn't refresh
public delegate bool EnumThreadWindowsCallback(int hWnd, int lParam);
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);
[DllImport("user32.dll")]
static extern int GetWindowText(int hWnd, StringBuilder text, int count);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static public extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
private bool FindWindowByRx(int hWnd, int lParam)
{
Regex pattern = new Regex("Seneste nyt", RegexOptions.IgnoreCase);
StringBuilder windowTitle = new StringBuilder(256);
GetWindowText(hWnd, windowTitle, 255);
if (pattern.IsMatch(windowTitle.ToString()))
{
SetForegroundWindow(new IntPtr(hWnd));
return false; // abort search
}
else
{
return true; // keep on searching
}
}
private bool ActivateWindow()
{
return EnumWindows(new EnumThreadWindowsCallback(FindWindowByRx), new IntPtr());
uint KEYEVENTF_KEYUP = 2;
byte VK_CONTROL = 0x11;
byte VK_F5= 0x74;
keybd_event(VK_CONTROL, 0, 0, 0);
keybd_event(VK_F5, 0, 0, 0);
keybd_event(VK_F5, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
}
It only gets focus.