How can I extract a file from an embedded resource and save it to disk?

I’d suggest doing it easier. I assume that the resource exists and the file is writable (this might be an issue if we’re speaking about system directories). public void WriteResourceToFile(string resourceName, string fileName) { using(var resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { using(var file = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { resource.CopyTo(file); } } }

Google Apps Script: How to set “Use column A as labels” in chart embedded in spreadsheet?

Found it! Set the option useFirstColumnAsDomain to true with EmbeddedChartBuilder.setOption. This option appears to be undocumented. I found it by going to “Publish chart” (click on the chart, then select from the drop-down in the top right) and inspecting the JavaScript data structure in the given code. To be exact, I created a chart with … Read more

How do I add an image to a JButton

I think that your problem is in the location of the image. You shall place it in your source, and then use it like this: JButton button = new JButton(); try { Image img = ImageIO.read(getClass().getResource(“resources/water.bmp”)); button.setIcon(new ImageIcon(img)); } catch (Exception ex) { System.out.println(ex); } In this example, it is assumed that image is in … Read more

Loop through all the resources in a .resx file

You should always use the resource manager and not read files directly to ensure globalization is taken into account. using System.Collections; using System.Globalization; using System.Resources; … /* Reference to your resources class — may be named differently in your case */ ResourceManager MyResourceClass = new ResourceManager(typeof(Resources)); ResourceSet resourceSet = MyResourceClass.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true); foreach (DictionaryEntry entry … Read more

Eclipse exported Runnable JAR not showing images

Works fine for me. Check what you may have different. Example 1: (resources in src) Steps: File Structure Code package com.stackoverflow.test; import java.net.URL; import javax.swing.*; // Wild carded for brevity. // Actual code imports single classes public class Main { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ public void run() { URL url = … Read more

Storing WPF Image Resources

If you will use the image in multiple places, then it’s worth loading the image data only once into memory and then sharing it between all Image elements. To do this, create a BitmapSource as a resource somewhere: <BitmapImage x:Key=”MyImageSource” UriSource=”../Media/Image.png” /> Then, in your code, use something like: <Image Source=”{StaticResource MyImageSource}” /> In my … Read more