Include data files in a Silverlight app - silverlight

I have some XML files marked as "Content" that should be copied into the application's XAP file. How can I read these files from within Silverlight?
I know how to read files normally in .NET. So what I'm looking for is a way to find where Windows stuck the files and any realavent security issues.

This is not exactly how to read files from within the xap but if you just want to be able to load the files at runtime then this will work.
You can set the files to be embedded resources. You then get access to them using the following:
GetType().Assembly.GetManifestResourceStream(resourceName)
resourceName is the name of the file with a full namespace. E.g. if your assembly default namespace (set in project settings) is "foo" and your file is in a folder called "bar" then resourceName would be something like "foo.bar.MyFile.xml"

You should just be able to do an XDocument.Load an pass in the name of your file.

Related

How to access the source directory in codename one

I am currently trying to create a plugin-like library for my company.
I need to check if four directories exist within the project structure. As java.io.File is not available, I am pretty confused on how to check for existance of a file that needs to exist within the project structure?
The concrete use-case.
There will be four directories:
/entities
/converter
/attributes
/caches
Now if the developer uses this library and wants to access all, lets say "Person"-Entities from the server, he should be able to call
RestGet.getAll("Person");
and the library looks in the source directory of the project if there are these Files:
/entities/PersonEntity.java //<-- Stores the actual data
/converter/PersonConverter.java //<-- Converts the JSON answer of the server to the Object
/attributes/PersonAttributes.java //<-- An enum that is used to set the attributes of the object
/caches/PersonCache.java //<-- A simple Cache
How can I do this? I tried with FileSystemStorage, but it only tell me that I should use getAppHome()...
I don't quite understand the usage of the source directory which obviously won't exist on the device where your application is running.
You can get access to files in the root of your SRC directory which get packaged into the JAR using Display.getInstance().getResourceAsStream(...).
The replacement to java.io.File is FileSystemStorage which is covered in the developer guide.

Windows Phone 8.1 change/update localization strings at run time

I have tried to change the Resource.resx file at run time but it's impossible because during compile time all the .resx files for an app are packed into a single PRI file by the MakePRI utility and included with the app's deployment package.
For the time being I am trying to delete the ".resx" files and find another solution to create and retrieve the localization Strings files
Can you please help me by providing a solution for this problem, thank you
In fact, you should not delete your resw files but leverage this feature to build your own localization mechanism.
I have recently build a tool that updates resw files (they are just XML files) at runtime and can also read them. You have to ensure that your resw files at are not compiled by PRI, for this change the build action from PRIResource to Content and select Copy Always to ensure that the files are available in your output directory.
Unfortunately, you can't reuse ResXResourceReader class which is available for Windows Form application, but you can easily write a class that is able to read and modify these entries. The format for localized data in the resw files is the following:
<data name="Name1">
<value>this is my long string</value>
<comment>this is a comment</comment>
</data>
Then you add a class that just open the expected localization files based on the user locale. And you pass the stream to the parser which will extract the localized string based on its identifier.

How to put all the files used inside the winform application in the exe itself?

I am making a winform application whereby I am using some images to show .It works fine when run . But what if I want to take the exe out from the debug folder and use it in some other machine then it will give exceptions that it can't find images on the same path(its obvious as it is not there in that machine path).
Idea to overcome this is to make a setup out of it,but that too is a tedious task.
Can it be possible that we can accomodate all the other sources(like images) used in the project in such a way that it should go along with the exe ?
It's a kind of an odd error, because the *.exe file in the Debug folder is created after adding all the resources into it. And that's why the *.exe file gets lager in size. But it will be a problem if you have mentioned the paths of the resources (like images) manually.
To avoid that always use the properties panel to import resources to the project and this will create the Resoures.resx automatically. Then all the resources will stick to the *.exe file.
But if you have mentioned the paths manually you must provide them in the targeted computer which you are going to use the *.exe file. To make it more easier, give a path in the same folder where the *.exe file exist.
For example give simple paths like (#"image.jpg"), without giving paths like ("C:\Users\Sam\Pictures\image.jpg").
And create a setup including all the resources like images, databases, etc.

File path in app.config file ? Window application?

In window application, I am accessing one file and the file path is declared in app.config file. After that I create exe for that application. Now the problem is when path is changed in app.config file when setup is created is this changes updated in setup or not?. If yes, how can I do that?
Its better to use relative paths, but As I understand, you cant use they.
So, only one possible solution in my opinion - define file path during instalation or add special dialog on programm first run to let user to define the path.

Storing resources in XAP package

Is it possible to store resx files and access them from the application package without changing any code?
EDIT: I don't want to embed them into the assembly. The resource files should be able to be modified without compiling the project so I tought storing them in XAP and replace when needed.
Thanks.
It is possible to include any file in a XAP by specifying that its build action to be Content.
However I'm not sure that is useful to you in the way you are hoping. Silverlight can only utalise a resx file in the intended manner if it is embedded in a dll.
Instead of using .resx files consider using ResourceDictionary .xaml files.
a XAP file is encrypted. you could load resources into isolated storage and access them in a similar way to a resource.

Resources