Ask a Question related to ASP.NET Building Controls, Design and Development.
-
Jon Paal #1
image resources
1] how can images be stored as resources in a dll and
2] how to retrieve them for usage in a custom assembly ?
Jon Paal Guest
-
MX 7 uses more resources than MX 6.1?
I administrate a website, that is viewed by 18.000 unique users. Coldfusion MX 6.1 is running on the server. I decided to try Coldfusion MX 7.... -
Does 802.11b use a lot of resources?
Have I tried too hard to squeeze usability out of an old computer? I have a Pentium-166 that has been a faithful router & firewall (FreeBSD 5.3... -
out of OS resources
I don't think that this message is fatal since the error code indicates the situation is temporary. ----- Original Message ----- From: "jorge... -
web resources
Hello I'd like to learn asp, but it seems impossible to find free resources. Does anyone knows sites that offer tutorials, sample scripts and a... -
apt resources
Hello all. Can anyone suggest, or would you even recommend at all for that matter, some good non-official apt sources for debs that are not... -
Teemu Keiski #2
Re: image resources
1) In Visual studio, set tbuild action to embedded resource for the image
file when they are embedded to the dll as resource (note you want to do that
in a class library project for web resources to work)
2) Assuming you have reference to the assembly (via Type.GetType etc) then
by calling Assembly.GetManifestResourceStream is one way. Another is to use
web resources. See: [url]http://aspalliance.com/726[/url]
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
[url]http://blogs.aspadvice.com/joteke[/url]
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message
news:%23XEVJXP1GHA.4448@TK2MSFTNGP04.phx.gbl...> 1] how can images be stored as resources in a dll and
>
> 2] how to retrieve them for usage in a custom assembly ?
>
Teemu Keiski Guest
-
Brennan Stehling #3
Re: image resources
What you need to do is place your files into a class library. Set the
Build Action property for the file you want to embed as an Embedded
Resource. This will cause it to be included in the assembly.
Next you need tag it with AssembyInfo.cs. Assume you have a default
namespace of XYZ and place your embedded files into a folder called
Resources. The namespace for that folder will automatically be
XYZ.Resources.
In your AssemblyInfo.cs you need to add reference to it.
[assembly: WebResource("XYZ.Resources.Icon1.jpg", "image/jpeg")]
That will make it available as a web resource. Now you want to get the Url
to access the content.
string url = Page.ClientScript.GetWebResourceUrl(GetType(),
"XYZ.Resources.Icon1.jpg");
Notice it calls GetType(). That is used to tell it which assembly to use to
load the resource. You may want to place a dummy class in your assembly and
use it as a reference here. You may even want to provide a class called
ResourceLoader.cs and give it useful Properties.
public static string Icon1Url {
get {
return Page.ClientScript.GetWebResourceUrl(GetType(),
"XYZ.Resources.Icon1.jpg");
}
}
Then you just access static properties to access your resources.
Brennan Stehling
[url]http://brennan.offwhite.net/blog/[/url]
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message
news:%23XEVJXP1GHA.4448@TK2MSFTNGP04.phx.gbl...> 1] how can images be stored as resources in a dll and
>
> 2] how to retrieve them for usage in a custom assembly ?
>
Brennan Stehling Guest
-
Jon Paal #4
Re: image resources
sample code which is failing to display the image
================================================== ==
Assembly code................
<Assembly: WebResource("Logo.gif", "image/gif")>
code ...............
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Web
Imports System.Web.UI
Imports Microsoft.VisualBasic
NameSpace namespace1
Class class1
Inherits System.Web.UI.Page
Implements IHttpHandler
Public Function showimg() As String
Dim Response As HttpResponse = HttpContext.Current.Response
Dim returnValue As String = String.Empty
returnValue = Page.ClientScript.GetWebResourceUrl(Me.GetType(), "Logo.gif")
response.write( "<img src=""" & returnValue & """>")
End Function
End Class
End Namespace
viewsource output for image is ...................
<img src="/WebResource.axd?d=whMLBJ8IDJGvV_odhtKmwHKuto9Ppv4U 7VgziTrNxAtrvyWBq8_A4mRnZzRjVosI0&t=63293579222000 0000">by using
reflector I can see the image is stored in the DLL as a resource and is correctly named, but it does not display in the web
page.What am I missing ?????
Jon Paal Guest
-
Jon Paal #5
Re: image resources
I'm not using visual studio ....
"Teemu Keiski" <joteke@aspalliance.com> wrote in message news:eBHMk9d1GHA.1256@TK2MSFTNGP04.phx.gbl...> 1) In Visual studio, set tbuild action to embedded resource for the image file when they are embedded to the dll as resource (note
> you want to do that in a class library project for web resources to work)
>
> 2) Assuming you have reference to the assembly (via Type.GetType etc) then by calling Assembly.GetManifestResourceStream is one
> way. Another is to use web resources. See: [url]http://aspalliance.com/726[/url]
>
> --
> Teemu Keiski
> ASP.NET MVP, AspInsider
> Finland, EU
> [url]http://blogs.aspadvice.com/joteke[/url]
>
>
> "Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message news:%23XEVJXP1GHA.4448@TK2MSFTNGP04.phx.gbl...>>> 1] how can images be stored as resources in a dll and
>>
>> 2] how to retrieve them for usage in a custom assembly ?
>>
>
Jon Paal Guest
-
Jon Paal #6
Re: image resources
I've also tried :
namespace1.Logo.gif
namespace1.Resources.Logo.gif
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message news:enEkiAo1GHA.4312@TK2MSFTNGP02.phx.gbl...> sample code which is failing to display the image
>
> ================================================== ==
>
> Assembly code................
> <Assembly: WebResource("Logo.gif", "image/gif")>
>
>
> code ...............
> Imports System
> Imports System.ComponentModel
> Imports System.Drawing
> Imports System.Web
> Imports System.Web.UI
> Imports Microsoft.VisualBasic
>
> NameSpace namespace1
>
> Class class1
> Inherits System.Web.UI.Page
> Implements IHttpHandler
>
> Public Function showimg() As String
>
> Dim Response As HttpResponse = HttpContext.Current.Response
> Dim returnValue As String = String.Empty
> returnValue = Page.ClientScript.GetWebResourceUrl(Me.GetType(), "Logo.gif")
> response.write( "<img src=""" & returnValue & """>")
>
> End Function
>
> End Class
> End Namespace
>
> viewsource output for image is ...................
>
> <img src="/WebResource.axd?d=whMLBJ8IDJGvV_odhtKmwHKuto9Ppv4U 7VgziTrNxAtrvyWBq8_A4mRnZzRjVosI0&t=63293579222000 0000">by using
> reflector I can see the image is stored in the DLL as a resource and is correctly named, but it does not display in the web
> page.What am I missing ?????
>
Jon Paal Guest
-
Brennan Stehling #7
Re: image resources
Your web page will not be in the same assembly as the embedded
resource. The reference to Me.GetType() will not work for you.
You need to reference a class which is in the same assembly as the one
you want to access.
And both VB.NET and C# in .NET 2.0 have a default namespace, so if you
set that default root namespace to XYZ, and place your embedded file,
logo.gif, in the root folder you will use this reference.
XYZ.logo.gif
Brennan Stehling
[url]http://brennan.offwhite.net/blog/[/url]
Jon Paal wrote:> I've also tried :
>
> namespace1.Logo.gif
> namespace1.Resources.Logo.gif
>
>
>
>
>
>
> "Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message news:enEkiAo1GHA.4312@TK2MSFTNGP02.phx.gbl...> > sample code which is failing to display the image
> >
> > ================================================== ==
> >
> > Assembly code................
> > <Assembly: WebResource("Logo.gif", "image/gif")>
> >
> >
> > code ...............
> > Imports System
> > Imports System.ComponentModel
> > Imports System.Drawing
> > Imports System.Web
> > Imports System.Web.UI
> > Imports Microsoft.VisualBasic
> >
> > NameSpace namespace1
> >
> > Class class1
> > Inherits System.Web.UI.Page
> > Implements IHttpHandler
> >
> > Public Function showimg() As String
> >
> > Dim Response As HttpResponse = HttpContext.Current.Response
> > Dim returnValue As String = String.Empty
> > returnValue = Page.ClientScript.GetWebResourceUrl(Me.GetType(), "Logo.gif")
> > response.write( "<img src=""" & returnValue & """>")
> >
> > End Function
> >
> > End Class
> > End Namespace
> >
> > viewsource output for image is ...................
> >
> > <img src="/WebResource.axd?d=whMLBJ8IDJGvV_odhtKmwHKuto9Ppv4U 7VgziTrNxAtrvyWBq8_A4mRnZzRjVosI0&t=63293579222000 0000">by using
> > reflector I can see the image is stored in the DLL as a resource and is correctly named, but it does not display in the web
> > page.What am I missing ?????
> >Brennan Stehling Guest
-
Jon Paal #8
Re: image resources
I don't have/use Visual Studio ...
Is this assignable in the assembly info file ?
"Brennan Stehling" <offwhite@gmail.com> wrote in message news:1158180667.113934.195350@i3g2000cwc.googlegro ups.com...> Your web page will not be in the same assembly as the embedded
> resource. The reference to Me.GetType() will not work for you.
>
> You need to reference a class which is in the same assembly as the one
> you want to access.
>
> And both VB.NET and C# in .NET 2.0 have a default namespace, so if you
> set that default root namespace to XYZ, and place your embedded file,
> logo.gif, in the root folder you will use this reference.
>
> XYZ.logo.gif
>
> Brennan Stehling
> [url]http://brennan.offwhite.net/blog/[/url]
>
> Jon Paal wrote:>>> I've also tried :
>>
>> namespace1.Logo.gif
>> namespace1.Resources.Logo.gif
>>
>>
>>
>>
>>
>>
>> "Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message news:enEkiAo1GHA.4312@TK2MSFTNGP02.phx.gbl...>> > sample code which is failing to display the image
>> >
>> > ================================================== ==
>> >
>> > Assembly code................
>> > <Assembly: WebResource("Logo.gif", "image/gif")>
>> >
>> >
>> > code ...............
>> > Imports System
>> > Imports System.ComponentModel
>> > Imports System.Drawing
>> > Imports System.Web
>> > Imports System.Web.UI
>> > Imports Microsoft.VisualBasic
>> >
>> > NameSpace namespace1
>> >
>> > Class class1
>> > Inherits System.Web.UI.Page
>> > Implements IHttpHandler
>> >
>> > Public Function showimg() As String
>> >
>> > Dim Response As HttpResponse = HttpContext.Current.Response
>> > Dim returnValue As String = String.Empty
>> > returnValue = Page.ClientScript.GetWebResourceUrl(Me.GetType(), "Logo.gif")
>> > response.write( "<img src=""" & returnValue & """>")
>> >
>> > End Function
>> >
>> > End Class
>> > End Namespace
>> >
>> > viewsource output for image is ...................
>> >
>> > <img src="/WebResource.axd?d=whMLBJ8IDJGvV_odhtKmwHKuto9Ppv4U 7VgziTrNxAtrvyWBq8_A4mRnZzRjVosI0&t=63293579222000 0000">by using
>> > reflector I can see the image is stored in the DLL as a resource and is correctly named, but it does not display in the web
>> > page.What am I missing ?????
>> >
Jon Paal Guest
-
Brennan Stehling #9
Re: image resources
Sorry I did not get back to you sooner. Without a version of Visual
Studio which can work with class library projects, you will have some
difficulty. To get around it to create assemblies with embedded
resources you can instead use MSBuild.
Below is a modified copy of a C# project file. Changing it from csproj
to vbproj may be all you need to do to make it a VB project. You can
use MSBuild to compile this project. Note the ItemGroup listing the
EmbeddedResource elements. You can edit that to add to your embedded
resources. I also set the default namespace to XYZ which you can
change.
What you will need below the folder holding this .csproj file is a
Properties and Resources folder for these files...
Properties\AssemblyInfo.cs
Resources\icon1.jpg
Resources\icon2.jpg
In AssemblyInfo.cs you will want this code, or for VB.NET you just
adjust the brackets.
C# version:
[Assembly: WebResource("XYZ.Resources.icon1.gif", "image/gif")]
[Assembly: WebResource("XYZ.Resources.icon2.gif", "image/gif")]
VB.NET Version:
<Assembly: WebResource("XYZ.Resources.icon1.gif", "image/gif")>
<Assembly: WebResource("XYZ.Resources.icon2.gif", "image/gif")>
# library.csproj
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == ''
">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9EAB7BCD-B236-48C2-A986-BA0261935041}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>XYZ</RootNamespace>
<AssemblyName>XYZ</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\icon1.jpg" />
<EmbeddedResource Include="Resources\icon2.jpg" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.target s" />
<!-- To modify your build process, add your task inside one of the
targets below and uncomment it.
Other similar extension points exist, see
Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
Brennan Stehling
[url]http://brennan.offwhite.net/blog/[/url]
Brennan Stehling Guest
-
Jon Paal #10
Re: image resources
Thanks for replying.
Actually, compiling is the easy part. Here is my solution that seems to work.
=========run command - adjust physical paths as needed - line breaks for clarity============
vbc.exe
/target:library
/res:Logo.gif
/out:\bin\Test.dll empty.vb
/rootnamespace:myproject
=========== empty.vb ===========
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Reflection
Imports System.Web
Imports System.Web.Configuration
Imports System.Web.UI
<Assembly: WebResource("Logo.gif", "image/gif")>
NameSpace HandlerExample
Public Class SomeClass
End Class
End Namespace
========default.aspx==========
<%@ Page Language="vb" Debug="True" %>
<script runat="server">
Sub Page_Load
Dim img1 As String = String.Empty
img1 = Page.ClientScript.GetWebResourceUrl(GetType(myproj ect.HandlerExample.SomeClass) , "Logo.gif")
lit1.Text = ( "<img src=""" & img1 & """>")
End Sub
</script>
<asp:literal id="lit1" runat="server"/>
Jon Paal Guest



Reply With Quote

