Hi, i want open an .exe file using OpenFileDialog( ) in C#
The code i ve used is -
Stream strm;
StreamReader reader;
try
{
strm = OpenFileDialog1 .OpenFile();
reader = new StreamReader(st rm);
}
catch (Exception err)
{
string Message = err.Message + "\n\nCannot open "
+ OpenFileDialog1 .FileName;
MessageBox.Show (Message, "Open error",
MessageBoxButto ns.OK,
MessageBoxIcon. Error);
return;
}
reader.ReadToEn d();
reader.Close();
strm.Close();
But, I m getting an error..
Can anybody tell me the cause....
Thanx in advance
8 7379
Hi, i want open an .exe file using OpenFileDialog( ) in C#
The code i ve used is -
Stream strm;
StreamReader reader;
try
{
strm = OpenFileDialog1 .OpenFile();
reader = new StreamReader(st rm);
}
catch (Exception err)
{
string Message = err.Message + "\n\nCannot open "
+ OpenFileDialog1 .FileName;
MessageBox.Show (Message, "Open error",
MessageBoxButto ns.OK,
MessageBoxIcon. Error);
return;
}
reader.ReadToEn d();
reader.Close();
strm.Close();
But, I m getting an error..
Can anybody tell me the cause....
Thanx in advance
What is the error you are getting?
Do you want to read the bytes making up the file or do you want to run the .exe program?
What is the error you are getting?
Do you want to read the bytes making up the file or do you want to run the .exe program?
I want to open the .exe file and also ro run it.
The error message is- 'Index was outside the bounds of the array'
I want to open the .exe file and also ro run it.
The error message is- 'Index was outside the bounds of the array'
To run an executable program, you need to start a process for it.
Here's an example that I use to run the javac.exe command - using System;
-
-
using System.Diagnostics;
-
-
class Commands {
-
-
public static String compileJava (String file) {
-
-
Process p = new Process();
-
-
p.StartInfo.FileName = "javac";
-
-
p.StartInfo.Arguments = file;
-
-
p.StartInfo.UseShellExecute = false;
-
p.StartInfo.RedirectStandardOutput = true;
-
-
p.Start();
-
-
return p.StandardOutput.ReadToEnd();
-
-
-
-
-
}
-
-
-
public static void Main(String[] args) {
-
String output = Commands.compileJava("/home/Java/HelloCSharp.java");
-
-
Console.WriteLine(output);
-
}
-
-
}
-
Hi r035198x,
Thanx for reply
Actually i want to run the .exe file..so it must be opened using OpenFileDialog( )..
Also even if i try to open .txt file, its not opening...
I ve tried ur code in C# bt its not working...Can u plz send me C# code for the process..' If possible'....
Thnx in advance
Hi r035198x,
Thanx for reply
Actually i want to run the .exe file..so it must be opened using OpenFileDialog( )..
Also even if i try to open .txt file, its not opening...
I ve tried ur code in C# bt its not working...Can u plz send me C# code for the process..' If possible'....
Thnx in advance
It doesn't matter where you get the path from. set the full path of you .exe to be the process's StartInfo.FileN ame. If you get any errors then post the code you used and the error message that you got.
Plater 7,872
Recognized Expert Expert
It should be pointed out that if the EXE is running, you probably cannot open it to read in the bytes at the same time.
I am assuming you are showing the OpenFileDialog and handling the OK/Cancel button presses correctly before jumping to that line of code.
Thanx,
My problem is solved..
i used System.Diagnost ic.Process.Star t("Path")
Thanx very much
Thanx,
My problem is solved..
i used System.Diagnost ic.Process.Star t("Path")
Thanx very much
Glad you got it to work.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Stephen LeBlanc |
last post by:
I'm having an issue coding in VB.NET. I'm trying to
create a program that let's a user choose 2 files, using
the OpenFileDialog control:1 file exists and contains
data for extraction, the other file is to store the
output from doing some events in program. The problem is,
when the user clicks a button, that opens the
OpenFileDialog box, then types the name of the file that
he'd like the output to be stored in, it gives me a 'file
doesn't...
|
by: iwdu15 |
last post by:
how can i open a file i saved and place the info into different text boxes?
|
by: Scott M. Lyon |
last post by:
My application (a VB.NET 2003 WinApp) currently has first an OpenFileDialog
(asking for an input file to the process I'm working on), and then once the
user selects that, it brings up a FolderBrowserDialog box (asking for a
destination for the output files from the process to be saved).
The OpenFileDialog works beautifully.
The problem is, after the user selects the input file from the
|
by: Peter Duniho |
last post by:
I searched using Google, on the web and in the newsgroups, and found nothing
on this topic. Hopefully that means I just don't understand what I'm
supposed to be doing here. :)
The problem:
I am trying to use the SaveFileDialog class to get a filename, which is
subsequently opened for writing (write access, read sharing, but using
read/write sharing doesn't make the problem go away anyway). Sometimes, on
the statement where I...
|
by: gazza67 |
last post by:
Hi,
I want to do something that I thought would be simple but i cant seem
to work it out, perhaps someone out there could help me.
I want to browse for a file (it will be a word document), save the file
name to a string and then at some later stage open that file with word.
The operating system will be windows 2000 (dont know if that makes a
difference or not).
| |
by: johnlarson |
last post by:
I am using an openfiledialoge to open a dbf file in a windows app. the error I get is c:\myfile.dbf not an valid filename. here is my code
private void button1_Click ( object sender , EventArgs e )
{
System.Windows.Forms.DataGrid ZipCode=null;
System . IO . Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog ( );
openFileDialog1 . InitialDirectory =...
|
by: =?Utf-8?B?TmFt?= |
last post by:
Version: .NET Framework 2.0
In my Windows Forms application, how can I open a file in its native
program?. Let’s say a listbox displays a list of file names with full paths;
when a user double clicks on a file name, the file opens in its native
program, a Word document opens in a Word Application, an HTML file opens in
IE etc. etc. Much like search result pane of Windows Explorer Search utility.
Thank you
|
by: =?Utf-8?B?TWlrZTE5NDI=?= |
last post by:
This is an example that is supposed to work in VB
http://support.microsoft.com/kb/175512/en-us
After spending a couple of hours downloading and installing VB Express 2008
after someone told me it was easy, the thing doesn't work any better.
These two instruction lines are not functional
3. Place a Common Dialog control on the form.
4. From the Insert menu, select Module to add a single code module to the
project.
There is no Common...
|
by: sillybob123 |
last post by:
Hello,
I was hoping someone could help me with my recent problem i have 1 OpenFileDialog and i want the user to only open 1 sort of file so this is what i have
If ReadCon.GetName(OFD.FileName) = "CON " Then
GameSaveLoc = OFD.FileName
LoadCon()
Else
MessageBox.Show("You cannot use this kind of file!")
Save.Enabled = True
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |