Loading Embedded Resources ?
am 09.10.2007 21:33:52 von sk.rasheedfarhan
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
Re: Loading Embedded Resources ?
am 09.10.2007 22:04:22 von 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.GetManifestResourceStre am("DataManager.Script.xml")))
{
script = reader.ReadToEnd();
}
"Rasheed" wrote in message
news:1191958432.975364.23040@d55g2000hsg.googlegroups.com...
> 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
>
Re: Loading Embedded Resources ?
am 09.10.2007 22:39:45 von Chris Mullins
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.
--
Chris Mullins
"Rasheed" wrote in message
news:1191958432.975364.23040@d55g2000hsg.googlegroups.com...
> 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
>