How to load the content of a project file

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
RaduMihai
Posts: 4
Joined: Sat Mar 16, 2019 10:53 am

How to load the content of a project file

Postby RaduMihai » Wed Mar 20, 2019 5:23 am

Hi,

I would like to be able in my application to load the content of a project file
(text file, or json file containing some initial data) as in the attached picture.
I know that there was some time ago another topic "How do I get the contents of a file in a project" on the
same subject, but the solution exposed there is rather complicated and also not an elegant one.
It works, but I would prefer a more simple solution. In the answer to that topic, the moderator wrote :
"The process will be easier in a future update. With the current Beta version, here is how to do it:" but that was 2017
and I hope that in the actual version there is a better solution.

If there is such a possibility please be so kind and give me some info how to do it.

Thank you in advance.

My best regards,

RaduMihai
Attachments
LoadFile.jpg
LoadFile.jpg (200.73 KiB) Viewed 5885 times

JS-Support @Userware
Site Admin
Posts: 1142
Joined: Tue Apr 08, 2014 3:42 pm

Re: How to load the content of a project file

Postby JS-Support @Userware » Thu Mar 21, 2019 12:08 pm

Hi,

Sure. You can use Application.Current.GetResourceString(fileName) where fileName is either in the format "ms-appx:///AssemblyName/FolderName/FileName" or "/AssemblyName;component/FolderName/FileName".

Please make sure that the "build action" of your file is set to "Content" in the file properties. You can verify that the file has been properly copied to the "bin\Debug\Output\app-cshtml5\res\AssemblyName\FolderName\FileName"

Thanks.
Regards
JS-Support

RaduMihai
Posts: 4
Joined: Sat Mar 16, 2019 10:53 am

Re: How to load the content of a project file

Postby RaduMihai » Thu Mar 21, 2019 1:47 pm

Hi,

Thank you for the answer.

First I have to make some corrections to the answer :

- correctly is Application.GetResourceString(new Uri(filename));
- "Build action" has to be "Resource" not "Content"

This solution works fine for files of type: ".config", ".txt", ".xml", ".json", but how to
load other files (of any type, binary files, etc)?

I have tried Application.GetResourceStream, but I got an exception :
exception.jpg
exception.jpg (24.88 KiB) Viewed 5697 times

It is weird that the error message is about GetResourceString and not GetResourceStream.

Do you have any other idea of a possible solution to load any file?

Best regards,
RaduMihai

RaduMihai
Posts: 4
Joined: Sat Mar 16, 2019 10:53 am

Re: How to load the content of a project file

Postby RaduMihai » Sat Mar 23, 2019 6:25 am

Hi,

For everyone who is interested about this subject, I have an idea how to load any file : convert the file
to base64, load as a text file and convert back from base64 to byte array.

Best regards,

RaduMihai


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 25 guests

 

 

cron