Default edit application - c#

Trying to open an image for editing in C#
I can open the file with
System.Diagnostics.Process.Start(fileItem.Path);
This seems to issue the default open command which in my case for jpg files is standard preview, is there any way to use Process to open the file with the associated "Edit" command.

You can use the Verb-Property of the ProcessStartInfoclass
See MSDN
ProcessStartInfo startInfo = new ProcessStartInfo("myfile.jpg");
startInfo.Verb = "edit";
Process.Start(startInfo);

Related

Open Edge in a new process and kill it again

I'm currently making a program, that essentially needs to open a link in Edge, take a screenshot and then close the browser again.
1st issue:
I can open the browser just fine, but it just opens a new tab instead of a new window, if the browser's already open.
I do not want to interfere with an already existing open Edge browser, that our users may be using, but instead open a completely new instance, take a screenshot and then close it again.
I tried using the following, with no luck - it still just opens a new tab
Process proc = new Process();
proc.StartInfo.FileName = "microsoftedge.exe";
proc.StartInfo.Arguments = "http://172.31.44.1/#/cameras" + " --new-window";
proc.Start();
2nd issue:
When trying to kill the process using proc.Kill() I end up getting a system.invalidoperationexception cannot process request because the process has exited , but the browser's still open
Any help is appreciated!
Thank you in advance
Check this out:
using System.Diagnostics;
Process proc = new Process();
proc.StartInfo.FileName = #"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
proc.StartInfo.Arguments = " --new-window http://google.com";
proc.Start();
It seems as though Chrome (and therefor also Edge) has changed the behavior of this recently.
It used to be the case that you could use the parameter "--no-service-autorun" to avoid the browser closing the original process, and to avoid you ending up with an invalid (dead) process id.
This doesn't work anymore.
When "Startup boost" is disabled in Edge, the first window does have the correct process id, but anything after that is still invalid.
The only thing that I could find that works, is to use "--user-data-dir" parameter to give each process it's own profile and process.
For example, use "msedge.exe --user-data-dir=C:\test123" (make sure each process has a unique directory).

Automate converting office documents to pdf in c#

I am working on converting word docs and excel to pdf and automate the whole process. We have a server application that prints all the .doc and .xls files using COM interop and we want to have those files converted to PDF instead of printing them. I referred to How do I convert Word files to PDF programmatically? and also http://www.microsoft.com/en-us/download/details.aspx?id=7 to convert the documents to PDF and i was able to convert them. When i was doing some more research on the topic i found that it is not advisable to call Office Interop from Server Side application (Office documents to PDF), so i thought of using something like a PDF printer driver using which i can configure to bypass the Save As dialog. The i downloaded PDF995 and used the following code to test the output
string printerName = "PDF995";
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = (#"C:\...\test.XLS");
startInfo.Arguments = "\"" + printerName + "\"";
startInfo.CreateNoWindow = true;
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
//startInfo.UseShellExecute = true;
startInfo.Verb = "printto";
using (Process process = new Process())
{
process.StartInfo = startInfo;
process.Start();
if (!process.HasExited)
{
process.WaitForExit();
}
}
It works in my box and i need to test it in the server. I just realized while testing it, i am getting exception "No Process associated with this object" at the line (!process.hasexited) only for .xls files but not for .doc and .ppt files. I am wondering why, i tried to look at the Process Monitor (https://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) but could not find it. But it does work for .doc files without throwing the exception. Any idea why?
I would also like to know if there is a better way to go about it? I did take a look at the libraries like Aspose to convert word to pdf but the problem was we may have to purchase separate modules for word and another one for excel and one for slides which would be expensive. So we thought of using a printer driver which would be ideal to handle different types of documents.

Locating “Add Network Printer” 's exe location

I was keen on using the Process class [C#] to open "Add Printer" wizard, but I was wondering what is the location of the wizard's exe? And if so, is there a way to open straight into the "Add a network, wireless or Bluetooth printer" section of the wizard?
I would be glad if someone can help.
Thanks
You can do what you want by running a specific entry point in shell32.dll via rundll32.exe. The one you want is AddPrinter. For example;
ProcessStartInfo psi = new ProcessStartInfo {
FileName = "rundll32.exe",
CreateNoWindow = true,
Arguments = "shell32.dll,SHHelpShortcuts_RunDLL AddPrinter",
UseShellExecute = true
};
Process.Start(psi);
From a console run rundll32 printui.dll PrintUIEntry for a help dialog describing available command RunDll command lines.
To launch the Install UI you need to execute rundll32 printui.dll PrintUIEntry /il
(/ip for a Network Printer)

How to execute/open whatever file in .NET

If I have a path of any kind of file (.doc , .pdf , .png ...etc) and I would like to open that file as it is opened via double click (no need to determine the host program). An example of what I mean is: .doc file needs to be opened via MS Word or whatever word processor exists in the machine and it is set as defualt word processor.
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute.aspx
Process proc = new Process();
proc.StartInfo.FileName = "file.doc";
proc.StartInfo.UseShellExecute = true;
proc.Start();
Use Process.Start and pass the file name as an argument. This requires that the file extension be associated with the correct program.

Open windows explorer with WPF application directory

I want to open application directory with button click. i get such error
Does anyone have an idea?
If you set UseShellExecute to true, then you can use Process to open a directory. For example, this will open the C:\ drive. You can specify any path you want.
Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = #"C:\";
process.Start();
This is similar to using the Run dialog from the start menu. For instance, even though a Word document is not a program, using Shell Execute will allow you to "Start" a word document by using whatever program is associated with it. Likewise the same with a directory.
Have you tried "explorer.exe {0}" ? Explorer is the process you want, and the argument your intended path.
Try setting the ProcessStartInfo.Verb to "Open".

Categories

Resources