473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

GetManifestResourceStream

Hi,

I'm writing a WinForms app in C# which requires a 3rd party executable
called htmldoc.exe in order to create PDF documents from HTML files. To
prevent the app from not functioning if the user accidentally deletes this
file, I'm investigating the possibility of making it an Embedded Resource.
When the app starts up, it will search for the executable and "extract" it
if it's missing. I found the following code on the Net:

using Microsoft.Win32;
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;

byte[] abytFile;
Assembly objAssembly = Assembly.GetExecutingAssembly();
Stream objStream = objAssembly.GetManifestResourceStream("htmldoc.exe ");
abytFile = new Byte[objStream.Length]; // this line errors
objStream.Read(abytFile, 0, (int)objStream.Length);
FileStream objFileStream = new
FileStream(Path.GetDirectoryName(objAssembly.Locat ion) + "\\htmldoc.exe",
FileMode.Create);
objFileStream.Write(abytFile, 0, (int)objStream.Length);
objFileStream.Close();

This compiles with no errors, but errors on the line I've indicated. The
error string is:
System.NullReferenceException: Object reference not set to an instance of an
object.\r\n at HBQ.frmMDI.frmMDI_Load(Object sender, EventArgs e) in
c:\\documents and settings\\mrae\\my documents\\visual studio
projects\\hbq\\hbq\\frmmdi.cs:line 851

which indicates that the Stream has not been created correctly - if I hover
the cursor over the objStream variable, it shows "<undefined value>"

I'm slightly puzzled as to what I'm doing wrong - the executable is
definitely there and has been added to the project with its Build Action set
to Embedded Resource.

Any assistance gratefully received.

Best regards,

Mark Rae
Nov 16 '05 #1
1 5531
"Mark Rae" <ma**@markrae.co.uk> wrote in message
news:uT**************@TK2MSFTNGP10.phx.gbl...

D'oh! Forgot to prefix the resource filename with the project's default
namespace!

Sorry for the pointless post... :-(
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steve Guidi | last post by:
Hello, I'm developing an application that periodically reads embedded assembly resources. The resources are text-based, and are about 3-7KB in size, and the application accesses them by calling...
1
by: Mark Rae | last post by:
Hi, I'm writing a WinForms app in C# which requires a 3rd party executable called htmldoc.exe in order to create PDF documents from HTML files. To prevent the app from not functioning if the...
0
by: Darryn Ross | last post by:
Hi, I am trying to use GetManifestResourceStream and i keep getting a NULL exception error?? i cannot understand why? private Bitmap _buttonFace; .. ..
6
by: Saya | last post by:
Hello, This is a repost 'cause I haven't solve the problem: I can't use the System.Drawing class 'Image.FromStream' in the CompactFramework environment. What I've done with respect to Brendan's...
0
by: Leszek Taratuta | last post by:
Hello, I would like to retrieve an image from embedded resources. Then I need to use it in all over my web app, usually as an icon for ImageButtons. My idea was to retrieve the image just once...
15
by: kurt sune | last post by:
Anybody has a tip of where to find info/example how to retrieve an icon from a .RESX-file? /k
1
by: Tom Edelbrok | last post by:
I'm reading embedded bitmaps from an EXE project and everthing works fine. I do a GetExecutingAssembly, followed by setting a stream object to...
2
by: Jonathan Crawford | last post by:
Hi I downloaded a sample from here http://64.78.52.104/FAQ/WinForms/default.asp#44 5.57 How do I display a column of buttons such as pushbuttons or combobox buttons? I can run the project ok...
1
by: WT | last post by:
Hello, My 1.1 web site was using GetManifestResourceStream to get strategic .js files embedded as resources in the site assembly, but now it is no more allowed to embed resources by specifying a...
6
by: CSharpProgrammer | last post by:
Hi, I followed an example that loads an embedded resource http://support.microsoft.com/kb/324567 That works just fine and dandy. My problem is that my namespaces are setup a bit differently....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.