http://www.omegacoder.com/?p=63
In this article I describe how to get the current URL in Internet Explorer and the current directory in Windows Explorer. This works in .Net 2 and IE 7. I am showing both at the same time because they are similar in methods of getting the address of the items, whether its a hard drive or a URL.
First step requires the access ShellWindows object which represents a collection of open windows in the system. To access that object which resides in the SHDocVw namespace we need to import a Com library Microsoft Internet Controls in to the project:
image
With that we can access the ShellWindows object and begin our work. Here is the code sample
using System.IO;
...
SHDocVw.ShellWindows shellWindows
= new SHDocVw.ShellWindowsClass();
string filename;
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
filename
= Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore"))
Console.WriteLine("Web Site : {0}", ie.LocationURL);
if (filename.Equals("explorer"))
Console.WriteLine("Hard Drive : {0}", ie.LocationURL);
}
Thanks to the magic of ShellWindows we are able to see all active windows. We discriminate and get the names of the windows we are interested in and wala here is the output:
Hard Drive : file:///C:/Work/Net2
Web Site : http://www.omegacoder.com/
Subscribe to:
Post Comments (Atom)
1 comment:
SHDocVw.InternetExplorerClass ie=new SHDocVw.InternetExplorerClass ();
Object vHeaders = "Content-Type: application/x-www-form-urlencoded" + "\n" + "\r";
Object vPost = null;
Object vTarget = null;
Object vFlags = null;
string postData = "postvariable1=one&postvariable2=two";
vPost = System.Text.ASCIIEncoding.ASCII.GetBytes(postData);
ie.Navigate(http://url/,ref vFlags,ref vTarget,ref vPost,ref
vHeaders);
ie.Visible =true;
Post a Comment