Loading Embedded Resources/Files

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
 
H

harborsparrow

Something like this code should work, where xsltURL is a filepath like
"c:/rss.xsl":

public static string runTransform(string sourceURL, string
xsltURL)
{
//source
XmlTextReader reader = new XmlTextReader(sourceURL);
XmlDataDocument document = new XmlDataDocument();
document.Load(reader);

//target
StringWriter stw = new StringWriter();
XmlTextWriter xmlTextWriter = new XmlTextWriter(stw);
xmlTextWriter.Formatting = Formatting.Indented;

//transformation
XslCompiledTransform xslt1 = new XslCompiledTransform();
xslt1.Load(xsltURL);

// execute the transform and output the results to a file.
xslt1.Transform(sourceURL, xmlTextWriter);

//return HTML file
return stw.GetStringBuilder().ToString();
}
 
M

Mark Dykun

Rasheed,

Is it possible that you did not make the file an embedded resource. I am
guessing that this is the reason that you could not see the xslt file in the
assembly manifest.

Mark Dykun
VP Mobile and Integration Services, Castle CRM
 

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

Similar Threads


Top