Lets see how to embed a resource and get its coresponding URL.
Steps
- Create a web application.
- Add a resource into the project.Resource can be a file of any type.
- Right click on the project and click on 'Add existing item'
- It will show up a file open dialog.Select the file ,it will be added into your project.
- Goto properties of that resource and set build action to 'Embedded Resource'.
- Add the attribute for namespace as follows to denote this is a webresource
[assembly: WebResource("<namespace>.<filename>.<extension>","<mimetype>")]
Eg :[assembly: WebResource("WebResourceURLDemo.joy.jpg","image/jpg")] - Now you can refer the resource with the URL returned from the method Page.ClientScript.GetWebResourceUrl(typeof(class name), "<namespace>.<filename>.<extension>");
Eg:Page.ClientScript.GetWebResourceUrl(typeof(_Default), "WebResourceURLDemo.hello.jpg");
The URL will be pointing to WebResource.axd with some url parameters.These parameters help the system to identify the correct resource.
A sample can be downlaoded from here which stores an image in asp.net dll and refering through web resource url.
No comments:
Post a Comment