I'm trying to open something in ie via
System.Diagnostics.Process.Start("iexplore.exe", uniquePartOfUrl);
However this doesn't account for the fact a window is already open, if it is then I want to just use that. How could this be done?
IMO, the best way to open a web page is to use the following syntax:
Process.Start("http://www.mysite.com");
This way the OS will open it in the users default browser, and use the browsers tab functionality if it has that capability. Nothing annoys me more (ok, maybe some things do) than programs that force me to use a specific browser for no good reason, when I already selected which browser I want to use already. Honoring the users decision here is a good thing.
On CodeProject, there exists a project to "Capturing the Running IE Instances in C#"
It gives you one way to do it.
Using the WIN32 API, you can enumerate the windows opened, and filter them to get the running instances of IE.
It may be helpful for you.
You can try something like this:
var p = new System.Diagnostics.Process();
var s = new System.Diagnostics.ProcessStartInfo(uniquePartOfUrl);
s.UseShellExecute = true;
s.WindowStyle = ProcessWindowStyle.Normal;
p.StartInfo = s;
p.Start();
I don't have a compiler handy to test it right now, but the idea is that it should simply tell the OS to "open this URL" and let the OS decide how, which may use the existing window depending on the application. Worth a shot.
For reusing an existing window of IE, you can approach it in 2 different ways
Find the current instance of IE and then open it using that instance. This is covered by the answer given by #LaGrandMere
Set IE using the inbuilt settings to make it reuse itself. For using this method, you can follow the instructions given at this Microsoft support article.
Related
I am trying to open windows 7 help from a .Net form application to a specific bookmark, at printer installation for example.
I tried to open it in the same whay that I open Control Panel applets (Back & Restore in the example below).
ProcessStartInfo startInfo = new ProcessStartInfo(#"c:\windows\system32\control.exe", "/name Microsoft.BackupAndRestore");
startInfo.UseShellExecute = true;
Process.Start(startInfo);
But it doesn't work.
I didn't succeed neither to open the .exe.
Does anyone know how to do this?
IIRC HelpPane.exe works with .h1s files so if you have full path to such a file you can just use for example Process.Start (#"C:\myDir\myhelpfile.h1s"); to open it.
According to MS another option (most likely the recommenced one) is to host the HelpPane (which is basically a COM object!) - for details see http://msdn.microsoft.com/en-us/library/ms728715%28v=VS.85%29.aspx
Other important MSDN links are:
http://msdn.microsoft.com/en-us/library/bb757030.aspx
http://msdn.microsoft.com/en-us/library/ms728718%28v=VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms728713%28v=VS.85%29.aspx
From the above links:
The Help Pane API can only be used to display the Windows Help content
set. It can be customized by OEMs, system builders, and enterprise
customers under license agreement, but cannot be used by third-party
programs. Displaying content that is not part of the Windows Help
content set is not supported.
Depending on what you want to achieve you might need to first sign a license agreement with MS...
EDIT - as per comments:
To display a specific topic you need to call the method DisplayTask of the COM object with the URL of that topic.
EDIT 2 - as per comments the final solution:
Add a reference to C:\Windows\System32\HelpPaneProxy.dll to the project then you can use the HelpPane like this
HxHelpPane pHelpPane = new HxHelpPane();
pHelpPane.DisplayTask("mshelp://windows/?id=e725b43f-94e4-4410-98e7-cc87ab2739aa");
I am using the Windows API Code Pack for Microsoft .NET Framework to try out of some of the new UI features of the Win7 taskbar. I am coding in C#.
I have a question regarding jumplists. All of the sample code provided assumes that the entries on the jump list are used to call out to run a particular application or open a document, e.g. a text document in a MRU list or run mspaint.exe.
I would like to implement some items which allow me to set state in my own application (i.e. the app which is interacting with the taskbar). MSN Messenger does this, for example, when you can set your status (Busy, Offline etc.).
Try as I might, I cannot create a JUmpListItem or JumpListLink to behave in this way - it treats them as applications or documents.
Does anyone have any samples of how to create an item which raises an event in the same application that created it? I am sure it is simple but I am being very daft.
Many thanks for your help.
I believe what you'd want to do is to call your application with a special set of flags (i.e. launch the executable with certain arguments). At application start up, you'd check to see what flags are set, then send a message to the main instance of the application and then exit out of the new instance.
Using the TaskBarDemo, to open an item created by your application would have to be referenced, ie if your program created a PDF file you would do this:
jumpList.AddUserTasks(new JumpListLink(Path.Combine(systemFolder, "C:\\Program Files\\Adobe\\Reader 9.0\\Reader\\AcroRD32.exe"), "Open Adobe Reader")
{
IconReference = new IconReference(Path.Combine(systemFolder, "C:\\Program Files\\Adobe\\Reader 9.0\\Reader\\AcroRD32.exe"), 0)
});
Otherwise you would have to ensure that your application registered file associations, for recent or frequent items.
I had a few problems with jumplists with the API Pack, i now use VS 2010 Beta 2 and let shell handle the jumplists.
Hope this is helpfull.
These tasks are some sort of IShellLink. Then, you should call ICustomDestinationList's AddUserTasks. Look up samples in Windows 7 Training Kit.
I'm trying to setup some code to print to different trays on a photo copier depending on what the document is (different sizes, paper colours...). It is one particular type of copier so I am not too worried about the code working in other scenarios. I still want to show the print dialog, just with the settings having better defaults for each document.
I have managed to setup the majority of what I want using properties in
PrintDialog.PrinterSettings.
However on trying to set the duplexing using
PrintDialog.PrinterSettings.Duplex = System.Drawing.Printing.Duplex.Vertical;
It fails, remaining the same as it was before. If I check if duplex is supported using
PrintDialog.PrinterSettings.CanDuplex;
It returns false which is not the case I can change it on the dialog and it prints fine. Has anyone else had this problem? Is there a work around? Perhaps something involving COM (please be gentle not used interop code much)
It's a Gestetner 2212 copier and I believe the print server is a Windows Server 2008 machine.
Edit:
I found this link
http://bytes.com/topic/c-sharp/answers/238860-using-setprinter-c-set-duplex-option-print-prefs
Which seems to be a similar problem it seems to be some kind of problem related to using a networked printer and trying to set duplex. However the link doesn't post the solution it was emailed to them (I hate it when people do that). Anyone know how I can set the duplexing using COM interop code.
Seems network printers duplex property cannot be set in .NET code easily, even when it says it has changed the property it doesn't output correctly. There is a way to do it using com interop but it still requires modifying security levels for the printer so is more hassle than it is worth.
Try implementing a handler for the PrintPage event with following code:
if (e.PageSettings.PrinterSettings.IsValid && e.PageSettings.PrinterSettings.CanDuplex)
e.PageSettings.PrinterSettings.Duplex = System.Drawing.Printing.Duplex.Vertical;
Tried it with a HP Laserjet M3035. It didn't show in the PrintDialog window but printed the document in duplex anyway.
How to open files from explorer into different tabs. I can associate an open with menu with the file type, now when I already have the program working, how to open the new file into another tab, instead of new program.
How to find the already running process exactly, not with the name and send the filename to it.
Let me make myself clear: I want my app to be single instance, so that when user select 10 text files and press enter key, my application will open all the 10 text files into 10 tabs, instead of creating 10 processes. How to do that? How to communicate between various instances of the same process.
EDIT SOLVED: Implemented the functionality using WM_COPYDATA in C# and the SingleApplication class from codeproject.
I am not quite sure what you mean in this question. Are you trying to open Windows Explorer windows into one window with tabs? If that is the case, then I recommend you look into QT TabBar, which extends Windows Explorer to allow for such behavior.
Or perhaps you are trying to have a link open to a new tab in a web browser. If that is the case, this behavior is defined by the web browser itself. For Internet Explorer 7, you can set this behavior under Tools > Internet Options.
In the General tab, click the Settings button next to the "Tabs" section. You will want to set the "Open links from other programs in:" option to open a new tab.
Keep in mind that this behavior is defined by each user, and you can't ever make any guarantees that they will have the same browser settings as you do.
After reading your comments, I think I understand a bit better. It sounds like you want your application to only allow one instance at a time. Since you tagged this post C#, I will assume that is what you are writing your program in.
Codeproject.com has a great tutorial on how to make your program only allow a single instance.
Here is a snippet of code from their site:
static void Main()
{
if(SingleInstance.SingleApplication.Run() == false)
{
return;
}
//Write your program logic here
}
You would want to write code just before the return statement to have the existing instance open the file in a new tab.
If you are able to provide detailed information about what your program is doing, we might be able to help you with some of the specifics.
In a C# .NET 3.5 app (a mix of WinForms and WPF) I want to let the user select a folder to import a load of data from. At the moment, it's using System.Windows.Forms.FolderBrowserDialog but that's a bit lame. Mainly because you can't type the path into it (so you need to map a network drive, instead of typing a UNC path).
I'd like something more like the System.Windows.Forms.OpenFileDialog, but for folders instead of files.
What can I use instead? A WinForms or WPF solution is fine, but I'd prefer not to PInvoke into the Windows API if I can avoid it.
Don't create it yourself! It's been done. You can use FolderBrowserDialogEx -
a re-usable derivative of the built-in FolderBrowserDialog. This one allows you to type in a path, even a UNC path. You can also browse for computers or printers with it. Works just like the built-in FBD, but ... better.
Full Source code. Free. MS-Public license.
Code to use it:
var dlg1 = new Ionic.Utils.FolderBrowserDialogEx();
dlg1.Description = "Select a folder to extract to:";
dlg1.ShowNewFolderButton = true;
dlg1.ShowEditBox = true;
//dlg1.NewStyle = false;
dlg1.SelectedPath = txtExtractDirectory.Text;
dlg1.ShowFullPathInEditBox = true;
dlg1.RootFolder = System.Environment.SpecialFolder.MyComputer;
// Show the FolderBrowserDialog.
DialogResult result = dlg1.ShowDialog();
if (result == DialogResult.OK)
{
txtExtractDirectory.Text = dlg1.SelectedPath;
}
Unfortunately there are no dialogs other than FolderBrowserDialog for folder selection. You need to create this dialog yourself or use PInvoke.
So far, based on the lack of responses to my identical question, I'd assume the answer is to roll your own dialog from scratch.
I've seen things here and there about subclassing the common dialogs from VB6 and I think this might be part of the solution, but I've never seen anything about modifying what the dialog thinks it's selecting. It'd be possible through .NET via PInvoke and some other tricks, but I have yet to see code that does it.
I know it's possible and it's not Vista-specific because Visual Studio has done it since VS 2003.
Here's hoping someone answers either yours or mine!
After hours of searching for a similar solution I found this answer by leetNightShade to a working solution.
There are three things I believe make this solution much better than all the others.
It is simple to use.
It only requires you include two files (which can be combined to one anyway) in your project.
It falls back to the standard FolderBrowserDialog when used on XP or older systems.
The author grants permission to use the code for any purpose you deem fit.
There’s no license as such as you are free to take and do with the code what you will.
Download the code here.