how to run exe Embedded File

sarmad

Active member
Joined
Jan 22, 2006
Messages
37
Programming Experience
1-3
hi
first sorry for my poor english

i am newcomer and any help would be great

how i can put "exe" and "pdf" file like (foxit reader) and pdf document

(myfile.pdf) in my project.......


and when i need be able to run this exe file and open pdf file with it...


so thank
 
Just put them in the program folder or a subfolder. When you want to view the PDF with the EXE you just use this:
VB.NET:
Process.Start(Application.StartupPath & "\MyApp.exe", Application.StartupPath & "\MyDoc.pdf")
You can use a Setup project to distribute these files with your app if you want to.
 
thnaks for reply


but i dont want to use external application and i need to put this file

in the project and compile it with my project

something look like resources file

thanks
 
1) Add the .exe to your project and set Build Action to Embedded resource
2) Runtime: Retrieve the .exe for the resources and write to disk.
3) Run the .exe with the needed parameters

For instance something like this(some exception handling needed!):

VB.NET:
[COLOR=black][FONT=Courier New][COLOR=blue]Dim[/COLOR] assembly [COLOR=blue]As[/COLOR] System.Reflection.Assembly = _
                  System.Reflection.Assembly.GetExecutingAssembly()
[COLOR=blue]Dim[/COLOR] root [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR] = assembly.GetName().Name
[COLOR=blue]Dim[/COLOR] stream [COLOR=blue]As[/COLOR] System.IO.Stream = assembly.GetManifestResourceStream(root + [COLOR=maroon]"."[/COLOR] + [COLOR=maroon]"Runner.exe"[/COLOR])
[COLOR=blue]Dim[/COLOR] buffer(Convert.ToInt32(stream.Length) - 1) [COLOR=blue]As[/COLOR] [COLOR=blue]Byte[/COLOR]
stream.Read(buffer, 0, buffer.Length)
stream.Close()
[COLOR=blue]Dim[/COLOR] f [COLOR=blue]As[/COLOR] [COLOR=blue]New[/COLOR] IO.FileStream([COLOR=maroon]"Runner.exe"[/COLOR], IO.FileMode.Create, IO.FileAccess.Write)
f.Write(buffer, 0, buffer.Length)
f.Close()
Process.Start([COLOR=maroon]"Runner.exe"[/COLOR], [COLOR=maroon]"myfile.pdf"[/COLOR])
[/FONT][/COLOR]
 
Don Delegate said:
1) Add the .exe to your project and set Build Action to Embedded resource
2) Runtime: Retrieve the .exe for the resources and write to disk.
3) Run the .exe with the needed parameters
[/code]

thanks but
if run from cd ...this code cant to write the exe file to cd and the project

will not run

thanks
 
To save the files elsewhere as Don has suggested, you could use the System.IO.Path class's GetTempFileName or GetTempPath functions to save the files to the users temp directory.
 
VB.NET:
[COLOR=black][FONT=Courier New][COLOR=blue]Dim[/COLOR] assembly [COLOR=blue]As[/COLOR] System.Reflection.Assembly = _
                  System.Reflection.Assembly.GetExecutingAssembly()
[COLOR=blue]Dim[/COLOR] root [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR] = assembly.GetName().Name
[COLOR=blue]Dim[/COLOR] stream [COLOR=blue]As[/COLOR] System.IO.Stream = assembly.GetManifestResourceStream(root + [COLOR=maroon]"."[/COLOR] + [COLOR=maroon]"Runner.exe"[/COLOR])
[COLOR=blue]Dim[/COLOR] buffer(Convert.ToInt32(stream.Length) - 1) [COLOR=blue]As[/COLOR] [COLOR=blue]Byte[/COLOR]
stream.Read(buffer, 0, buffer.Length)
stream.Close()
[COLOR=blue]Dim[/COLOR] f [COLOR=blue]As[/COLOR] [COLOR=blue]New[/COLOR] IO.FileStream([COLOR=maroon]"Runner.exe"[/COLOR], IO.FileMode.Create, IO.FileAccess.Write)
f.Write(buffer, 0, buffer.Length)
f.Close()
Process.Start([COLOR=maroon]"Runner.exe"[/COLOR], [COLOR=maroon]"myfile.pdf"[/COLOR])
[/FONT][/COLOR]
[/quote]


hi

i have problem with my project

in the test form in another project this code work fine

but when test it in a original project i got this error


nullreference not set to an instance of an object
Object reference not set to an instance of an object.

what i have to do?

thanks
 
Probable cause is the resource that can not be found:
1) Did you set the Build Action to "Embedded Resource"?
2) Check the namespace / assembly for the resource.
3) Check the spelling of the name of the resource (I believe it's case sensitive)

Told you some exception handling was recommended.:)
 
yes
the build action is tue

and not any problem

whats the name space ?

3-check which one of speeling or name?

how ever thanks for reply

i wait for answer
 
Of course, everything is possible, but I don't think that's the cause of your problem (I could be wrong though).
1) How did you add the .exe and the .pdf to your project?
2) In what assembly did you add them? (.exe or other assembly)

Tip: build your project and have a look with Reflector to see if the resources are really there and under what name and in which assembly.
 
thanks

i got it and the file "file.exe" is there : project==>resources==>windowsapplication1.file.exe

now what i have to do?

i think that the source cant find the complete location of "file.exe"

is there any way to edit the source and place a full path of "file.exe"

what you think
where is the problem?
 
Back
Top