简体   繁体   中英

Embedded resource in C# asp.net

I have ac# windows application where I use sharppdf.dll to create pdf files on the fly. I have embedded certain bitmaps in my application by doing the following:

  1. Right Click Bitmaps and choose "Add Existing Item"
  2. Add the bitmap you want
  3. In the bitmap properties change "Build Action" to "Embedded Resource"

Then to include the bitmap I do the following:

sharpPDF.pdfDocument myDoc = new sharpPDF.pdfDocument("TEST", "ME", false);
sharpPDF.pdfPage     myPage;

Stream _imageStream;
_imageStream = _assembly.GetManifestResourceStream("MyClass.Bitmaps.ArrowUp.bmp");
Image img = new Bitmap(_imageStream);
myDoc.addImageReference(img, "ArrowUp");
myPage.addImage(myDoc.getImageReference("ArrowUp"), nX + 60, nY);

Now I wish to convert my application to the web, my question is how do I 'embed' my bitmap images in my C# asp.bet web application?? Or is there a different concept that I should use?

It completely depens on what you want to do with the images.

If those are part of the interface you want to show to the user, you simple put them all into a folder and reference them in your ASP.NET pages with HTML and CSS, like you would in a normal website.

I guess the fundamental difference here between Windows apps and Web apps, is that you own/control the files that are being used.

Whereby in a Windows app you had to include the files into the assembly that the user installed, in a Web app you can maintain the files in a separate folder within the application itself.

So, in your case here is the code I believe you are looking for:

using System.Drawing;
Bitmap img = new Bitmap(HttpContext.Current.Server.MapPath("~\[IMAGE FOLDER]\[IMAGE NAME]"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM