简体   繁体   中英

How to embed a Xslt file in a C# assembly?

I would like to embed a Xslt file in an assembly so that I can load the Xslt without having to read it from disk, and so that everything I need is contained within the exe.

i did this Xslt; enter image description here

C#

Assembly assembly = Assembly.GetExecutingAssembly(); 
Stream stream = assembly.GetManifestResourceStream("TimeSoft.Entities.Properties.Resources.general.Xslt");
StreamReader s = new StreamReader(stream);

I don't want to read the file. So I guess these codes are wrong. What i want is just get the file path how can i do that?

I have tried a test with a .NET framework 4.8 console app and an embedded file named sheet1.xsl in the project/assembly named XsltResourceNETFrameworkTest1 is found fine with using (var stream = assembly.GetManifestResourceStream("XsltResourceNETFrameworkTest1.sheet1.xsl")) . So this seems to work, you just need to get the assembly name and file name right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM