.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Saving Canvas and other UIElements as embedded resource

Posted By:      Posted Date: September 01, 2010    Points: 0   Category :WPF
Hi All, I am trying to save a canvas and its content as an embedded resource to another assembly but in doing so I got a Non-Serializable exception. Is there a better way of doing this? Here is the code I used in embedding the Canvas: // create an assembly AssemblyName assemblyName = new AssemblyName(System.IO.Path.GetFileNameWithoutExtension(filename)); AssemblyBuilder assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave); ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(assemblyName.Name, assemblyName.Name + ".dll"); // create a class TypeBuilder typeBuilder = moduleBuilder.DefineType("ModuleName", TypeAttributes.Public, typeof(EmbeddedBAML)); // Create a default constructor ConstructorBuilder constuctorDefault = typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes); ILGenerator ilGenerator = constuctorDefault.GetILGenerator(); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Call, typeof(EmbeddedBAML).GetConstructor(Type.EmptyTypes)); ilGenerator.Emit(OpCodes.Ret); typeBuilder.CreateType(); IResourceWriter resourceWriter = assemblyBuilder.DefineResource(assemblyName.Name + ".canvas", "Contains the Canvas object",assemblyName.Name + ".canvas", ResourceAttributes.Pu

View Complete Post

More Related Resource Links

Unique Pack URIs for resources (embedded / content / resource files) in several assemblies

Hello, When using resources as files (build actione=none and copy if newer), I'm able to manage resources using something like this : "/file.ico". Whatever the owner assembly is, because all files are copied in the Debug / Release directory. I'd like to have a similar behavior with pack URIs. I don't want to specify which assembly is the owner of an embedded / content / resource file. It seems impossible because we need to specify the source assembly ("pack://assembly_08:,,,/file.ico"), I'd like something like : "pack://whatever_the_assembly:,,,/file.ico". Is it possible ? Any idea ? Thanks.

Setting form icon from embedded resource in layout

I have no trouble embedding resources into my project into the resx file and using them for things like ImageLists. For example selecting a background image for a control, I simply click on the [...] button in the properties window for background image and a popup window allows me to select "Project resource file: Resources.resx" and lists the selectable images I've already embedded to choose from.
Yet how come when I select a Form and click [...] to select its icon it forces me to browse on my hard disk for a file instead of linking directly to the already-embedded resource? I don't want to have to keep adding copies of the same icon for every form I want to apply it to. Is there a reason for this or a way around getting this to work properly using the layout manager? I've found some pages that talk about how to code it into the source and force it to work that way but I'd like to know how to do it in the designer.

error in sharepoint 2010 designer while saving:"Content in the embedded form may be changed by the t

I am doing development  in sharepoint 2010 and facing this very weird problem.
If I create a site page with the sharepoint look and feel for that site and try to save the site page,i am getting this error:**"Content in the embedded form may be changed by the the server to remove unsafe content.Do you want to reload your page to see the results of the save? "** and when i say reload,the server removes some parts of my page, e.g onclick event of html,asp buttons.

This error just comes for any sharepoint site page,e.g i took a copy of 'How To Read Library' page just edited the text part of taht page,and when i try to save this error again comes up.

However,if i create a simple aspx page with only htmltags like head body,then thr is no problem ,everything works great. But sharepoint look and feel pages are giving troubles while saving.

has anybody seen this earlier,what could be the reason for this?


Jscript as an embedded resource failing


I have a straight forward control that I am trying to embed a js script file as a resource for and I am having issues. It appears that the resource is being made and the webresource.axd line is included in the source of the rendered page, however when i try to access a function in the script it fails and pops the Object Required error. I have followed countless examples and the concept pretty straight forward, I just can't find the error, please help.

In the debugging code at the bottom the GetManifestResourceInfo returns null however the GetManifestResourceStream does appear to return the embedded resource.


protected override void  OnLoad(EventArgs e)
        Type rsType = this.GetType();
        ClientScriptManager cs = Page.ClientScript;

        if (!cs.IsClientScriptIncludeRegistered("ScrollingListBox"))

            cs.RegisterClientScriptInclude("ScrollingListBox", cs.GetWebResourceUrl(rsType, "KustomCControls.Javascript.ScrollingListBox.js"));
            if (!cs.IsClientScriptIncludeRegistered("ScrollingListBox"))
                throw new Exception("boom");
            //cs.RegisterStartupScript(rsType, "ScrollableListBoxStartup" + this.UniqueID, string.Format("__ScrollableListBoxRefineHeightAndWidth('{0}');", this.ClientID), true);

problems running exe as an embedded resource from memory

i'm having some problems running exe from an embedded resource in memory
 public class Searcher
    public static void RunSearch(string path, string text)
      //Get the current assembly
      Assembly assembly = Assembly.GetExecutingAssembly();

      //Get the resource stream
      Stream resourceStream = assembly.GetManifestResourceStream("App.Utils.Search.exe");

      //Verify the internal exe exists
      if (resourceStream == null) return;

      //Read the raw bytes of the resource
      byte[] resourcesBuffer = new byte[resourceStream.Length];


The Free Barcode Creator produces barcode images one at a time, and allows easy saving to a file or

The Free Barcode Creator produces barcode images one at a time, and allows easy saving to a file or pasting into an application. 2D versions are also available:

Does this look correct for saving a file/ new record to a database


So thank you for all your help so far, So I think i got this right,
but would like for you all to look it over to see if there is any
areas I might run into trouble with:

//using asp.net mvc 2
the table (sql server 2005, using entities framework)
table fields
"Pattern_Media_GUID  uniqueid 
"Pattern_GUID  uniqueid
"Media varbinary(max)  
"height int
"Width int
"Media_Type String (50)

the form:
<h2> Add Media to this pattern</h2>
<% Html.EnableClientValidation(); %>
<% Html.BeginForm("AddMedia", "Pattern", new { id= Model.Pattern_Guid} , FormMethod.Post, new {enctype = "multipart/form-data"}); %>
    <%: Html.Label("height") %>
    <%: Html.TextBox("height") %>

    <%: Html.Label("width") %>
    <%: Html.TextBox("width") %>

    <%: Html.Label("Media") %>
    <input type="file" id="Media" name="Media" />
    <input type="submit" name=

Printing resource files



I have some resource files for localization and would like to print them. When I try to print them in Visual Studio (with File -> Print...) the button is disabled. Does anyone know how to print them? (Without copying each into word or excel)

Thanks and regards,

Why not Dataset use to Saving?


Hie Friends,

I have searched on net and even i worked on 2 huge shipping projects.

Everywhere i found that while binding data to control use dataset but when we save, they recommend use command (use generic collection and create command object with store procedure) why not we use dataset as in .NET 2.0 it is improved lot and data adapter has new feature batchupdatesize.

why we need to create property page which maps to all column in a database.

E.g. if i have employee table with empid and empname in database then i use to create emp.cs with properties of empid and empname and use same properties for saving. If i use these properties for validation in business rule then no problem. But why we use them in saving for creating command object.


saving XML output from webservice


 I created a webservice that takes casenum as input and gives results as a dataset in an XML.

I could make a web client to display the resulting dataset in a grid view. Pls see my code copied below.

Now I want to create a console client that takes the casenum as input, to call the webservice and saves the resulting xml for further processing, but can't figure out how to just capture the xml to save. Here's the code for my web client. I would appreciate if you could help modify this tocapture the resulting xml to save file locally.

Thank You.

namespace ResultsWebServicesClient
    public partial class _Default : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)

        private void BindDataToGrid(string CaseNum)
            FG_Results results = new FG_Results();
            DataSet ds1 = new DataSet();
            ds1 = results.Get_FG_Results(CaseNum);
            GridView1.AutoGenerateColumns = true;
            GridView1.DataSource = ds1.Tables[0];

        protected void GetResults(object sender, EventArgs e)


Saving textbox data to MySql database in asp.net


Hi dear coders

though a very simple question to ask, but please tell me how to save and retrieve data in/from my textboxes to/from database (MYSQL) on submit button click.

i know its a very simple task but i cant make it done, so i request you to please send me some working example link or post any helpful code here in asp.net

i will be highly thankful for any kind help from you geniuses.



set messageTemplateResourceName from resource file in Validation appication block.



  I am using Validation application block in my project and want to set validation message from resource file, but not able to do that. I tried giving the path of resource file in messageTemplateResourceType and name of resource in messageTemplateResourceName. But it did not help as I only receive the message if I have set something in messageTemplate even after setting the resource file.

Here is my code:

<validator lowerBound="1" lowerBoundType="Inclusive" upperBound="250"
              upperBoundType="Inclusive" negated="false" messageTemplate=""
              messageTemplateResourceType="Asurion.jCare.Common.Resources.UIResources.PerilTypeAndDetailsSection, Asurion.jCare.Common.Resources, Version=, Culture=neutral, PublicKeyToken=null"
              tag="" type="Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator, Microsoft.Practices.Enterpris

how to make a css style background image be linked to an image in the resource file


hey guy, i need help in a very troubling matter. I want to make a textbox with a specific style, within this style a set of images as background parts, how can i attach these images to the custom control as whenever i take the .dll file and add it to the toolbar the images do not appear. So i tried to make them as resource files and their property as embedded in .resx file, so how to make the css style background image url to be linked to any of those image.

thanks in advance

Page Title from Resource file...



I have Resource file...

I am using following code for Display Lable Text...

<asp:Label ID="lblName" runat="server" Text="<%$ Resources:resource,NAME %>"></asp:Label>

and I want to use that name for page title...

so I used "me.page.resources.resource.NAME" in code behind page.

 but I want to use that NAME in

<%@ Page Language="VB"

Problem in accessing resource file dynamically.


Steps I have followed are
1.I have created myres.en-GB.resx file at C:.
2.then created locale specific myres.en-GB.resources using resgen at c: only,
resgen c:\myres.en-GB.resx
3.Linked the Resource File to Assembly using AL.exe which is giving me assembly at c: only.
Al /t:lib /embed:myres.en-GB.resources /out:ClassLibrary1.dll
4.I have created one web application using vs 2008 & then build it.
5.Then placed both resource file & dll in web applications Bin\en-GB folder.
6.Anf finally written code at page load like
 CultureInfo info = new CultureInfo("en-GB");
            Thread.CurrentThread.CurrentCulture = info;
            Assembly asd = Assembly.Load("ClassLibrary1");
            ResourceManager res = new ResourceManager("myres.en-GB", asd.GetSatelliteAssembly(info));
            string sdf = res.GetString("Lab1");

but after running application I m getting following error
MissingManifestResourceException", "Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "Cla

Can't read global resource in asp button


I have translated Text Ok in arabic and I have that placed in global Navig.resx file

<asp:Button ID

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend