Loading Embedded Resources ?

R

Rasheed

Hi ,

Requirement is, I have to load my Xslt file into Exe/DLL.

I have created one .Xslt file and C# code for the same to produce
on .Xml file, like this:

System.Xml.XPath.XPathDocument Xmlpath = new
System.Xml.XPath.XPathDocument(filename);
XslTransform xsl = new XslTransform();
Stream xmlStream = this.GetType().Assembly.GetManifestResourceStream
("SolutionNameSpaceName.FormatConvertion.xslt");
System.Xml.XmlReader xmlReader = new System.Xml.XmlTextReader(xmlStrea
m );
xsl.Load(xmlReader);
XmlTextWriter textWriter = new XmlTextWriter(OutputPath +
"OutputFile.xml ", UTF8Encoding .Defaul t);
xsl.Transform(Xmlpath, list, textWriter);


My problem is with this statement:
Stream xmlStream = this.GetType().Assembly.GetManifestResourceStream
("SolutionNameSpaceName.FormatConvertion.xslt");

I have given my Application nameSpace "." Xslt filename but it returns
null into xmlStream.

For more informaton: I have read some information regarding
http://www.aisto.com/roeder/dotnet/ assembly Reflector, but still I
am unable to do this.

By using Reflector I am unable to see the Xslt file information after
loading the my solution DLL.

thanks in advance
regards
Rs
 
M

Mark Dykun

Rasheed,

Ensure that your Namespace.FomatConvertion.xslt is all cased correctly and
also spelt correctly. Either of this will ensure that the resource is not
located. I use the same code for reading from the embedded resource as
follows

string script = string.Empty;

using (StreamReader reader = new
StreamReader(this.GetType().Assembly.GetManifestResourceStream("DataManager.Script.xml")))

{

script = reader.ReadToEnd();

}
 
C

Chris Mullins [MVP - C#]

If you add in the Resource using the design-time tools, you can do this in a
strongly types, really easy way.

To do this:
Add in a Resource file to project (Resource1.resx).

Double-click on the resource file, and add an existing item to it (on the
top: "Add Resource | Existing File").

For example, I added "MyFile.xslt" in just now.

This lets me type:
string s = Resource1.MyFile_xslt;

... and everything is nice and strongly typed, with no need for
GetManifestStream calls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top