296
Views
5
Comments
Read Resource File Path in Extension
Question

I have added resource file , i added the build action to binary and included the folder ! 

but i am still unable to read it ! how to read the file path after you added it as resource


i am using this code 



            var dirPath = Assembly.GetExecutingAssembly().Location;

            dirPath = Path.GetDirectoryName(dirPath);

             string HtmlFilePath = Path.GetFullPath(Path.Combine(dirPath, @"ATsPdfTemplate\pdf.html"));





            string Logo = Path.GetFullPath(Path.Combine(dirPath, @"ATsPdfTemplate\ats.png"));

            string Footer = Path.GetFullPath(Path.Combine(dirPath, @"ATsPdfTemplate\world_map.png"));




            var dirPath = Assembly.GetExecutingAssembly().Location;

            dirPath = Path.GetDirectoryName(dirPath);

             string HtmlFilePath = Path.GetFullPath(Path.Combine(dirPath, @"ATsPdfTemplate\pdf.html"));





            string Logo = Path.GetFullPath(Path.Combine(dirPath, @"ATsPdfTemplate\ats.png"));

            string Footer = Path.GetFullPath(Path.Combine(dirPath, @"ATsPdfTemplate\world_map.png"));

2020-11-25 10-45-32
Mostafa Othman
Champion

Hello Omar,

Try to set Build Action to Embedded Resource then use "assembly.GetManifestResourceStream()"

you can check following URL:

https://stackoverflow.com/questions/3314140/how-to-read-embedded-resource-text-file


UserImage.jpg
Omar AbdElhadi

Bro , i have many resources ! i need to read image path for example ! i dont want to read file test 

how to reach the path of that resource and read it 

2020-11-25 10-45-32
Mostafa Othman
Champion

you can follow same way to get path of file regardless its type

UserImage.jpg
Omar AbdElhadi

This only work with Resx file ! i dont use resx file bro ! 

i have local folder has the files ! 

UserImage.jpg
Omar AbdElhadi

i tried it and it didnt work 


        string MiniResult = string.Empty;

            var assembly = Assembly.GetExecutingAssembly();

            var resourceName = "OutSystems.NssPDFTest.pdf.html";


            using (Stream stream = assembly.GetManifestResourceStream(resourceName))

            using (StreamReader reader = new StreamReader(stream))

            {

                MiniResult = reader.ReadToEnd();

            }


in .net embeeded 



and in integration copy to application 


didnt work 

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.