How to modify configuration file for another C# assembly? - app-config

I have a .NET assembly A with app.config settings file generated by framework. Actually, it is called A.dll.config. I want to access and modify this settings file from another .NET assembly B. The problem is, the A.dll.config file for A is located somewhere in the current user profile directory, as it should be, and I don't know where to find it. I know only where the assembly A is located.
So, how can I locate the app.config file given the path to the assembly?
The other question is, what if the assembly A was not loaded at the first time I'm trying to access its configuration file from the B? I assume, the configuration file is not generated at this time. Is it possible to manually load the A to force it to generate appropriate configuration file?

Related

Finding file locations in offline softwares in C

At some point in my C program I have to deal with something like this.
FILE * fptr = fopen("/Parent/child/.../file.dat");
Which means in order to access any file I need to know it's location. That's all understandable.
But, how can I make this generic? In my computer "/Parent/child/.../file.dat" will work because that's where the file is stored, but I'm making a software to distribute to other users so the path obviously differs. My question is, how can I install a specific file into the user's computer such that I can know and get the location of that file. I a but confused about this concept so any resources that could help me understand it better would be greatly appreciated.
In Linux the default path to application files should be hardcoded. There is a standard which applications should follow. For example, architecture-independent files should go to /usr/share/ and then either your application name or, if you expect the data to be shared between applications, a generic category such as images. User-specific configuration files should go $HOME/.config/<app-name>. Older applications place their default configuration in $HOME/.<app-name> instead.
You should also provide an ability to override the default path to the data with a command line switch and/or an environment variable and/or a user configuration file (the location of the latter should also be overridable with a command line switch and/or an environment variable).
Some applications search for their data directory relatively to the executable position. An executable can know its own absolute path by reading /proc/self/exe symbolic link. For example, if an executable finds itself in /usr/local/bin/somename, it can look for /usr/local/share/<app-name> (two levels up from the executable name and down to share/<app-name>.).
Finally, if you distribute source code for the users to build, the file locations should be configuration parameters.

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.

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.

Include data files in a Silverlight app

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.

Access a local file in Silverlight

I want to get the string from a local file (probably a Csharp file), which is attached to current project and its build action was set to Compile. Is there any way to do that. I cannot set the files' build action into Resource.
Regards,
Jawahar
I'm not clear which of these two questions you're asking:
Question 1) Can I get the text of a source file used during compilation, after compilation?
Answer 1) You'd need to set the build action to Content or Resource to do that, but realize that means you'd be shipping your source with your xap, so make sure that's what you want to do (i.e. most employers probably wouldn't like this).
You can have the file added to the xap twice by using "Add -> Existing Item -> (pick the file) -> Add As Linked Item (the little drop-down arros next to Add buton)" and set one to Compile and one to Content/Resource to accomplish this.
Question 2) Can I access a local file on the hard drive of a user of the Silverlight application?
Answer 2) Yes, by using OpenFileDialog and having the user choose the file.
Or, if you're in a Trusted Out of Browser Application (SL4 and above), then you can use the System.IO APIs to access files in My Documents, My Pictures, My Videos or My Music (on Windows an Mac) without needing to prompt the user.
Or, if you're in a Trusted OOB app, running on Windows, you can use COM and access the full file system (up to what the user can see permission-wise), again without prompt.

Resources