Where can I store my config file using windows forms? - c#

I'm fairly new to windows forms and I was recently tasked with creating a simple software which will be deployed by USB drives to other companies. I made this software so during first run I check for a config.xml file. If it doesn't exist, I will send the user to a form to configure their first time setup. Next time I run the program, it skips this step since the config.xml file is found with its values. The problem is when I debugged this, I found the config.xml file alongside the executable, however when I ran this on a different computer, it stored it into the appdata virtual store. I read up on this and found out it has to do with write permissions.
Is there any way I can get around this without prompting the user to do anything extra on their part such as run as administrator? I also plan on saving the resulting reports generated by the use of this program and was hoping I can have XML files which can be easily found within the application folder.
*Note, I am aware of the built-in settings system but this also stores into appdata and if the executable is moved to another directly, it loses sight of that config and wants to create another.
EDIT : Please be aware I am trying to AVOID writing to the AppData folder. The software is packaged with Visual Studio Installer - Setup Project. A msi file is created which stores the application in C:\Program Files (x86)\\. Inside this directory I have the executable, the exe.config file which is generated, and any DLLs needed. This is the folder I am trying to also store the config.xml file but due to some windows magic, the code thinks its storing it here but in reality it is being stored in the virtualStore folder located in AppData.

Have you thought of using the C:\ most computers have this unlocked. alternitively use Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
the AppData folder is stored in the username space and requires no permission. (just remember to create a folder for your program to avoid conflicts)

It is a known issue due to security concerns that write permissions are limited.
More can be learned here.
Since no one was able to answer this, I will post my solution. Instead of packaging the solution using Visual Studio Installer tools. I install the application by copying the resulting executable from the build. This version of the application has write permissions that would have not existed if the application was installed using the resulting .msi from the Installer tools.

Related

Change file permissions - Windows Installer

How do I add write and modify permissions to a text file that will be installed in the Application Folder in the File System on Target Machine?
Your post seems to indicate that you are using Visual Studio setup projects, the Installer add-on.
Two basic points:
There is no support for doing this in Visual Studio setup projects, so you would need to write custom action code that alters those permissions. The code to do that is about security APIs, so you probably won't get an explicit answer here.
The most common reason people do this is that the application needs to update the file, and it fails because updating ProgramFiles folder content requires administrator privilege. If this is the case then your application design should be improved by having the file in (say) the User's Application Data folder, which has that name for the obvious reason that's the preferred location for such data.

Publishing C# application with VisualStudio

I have an application written in C# using VisualStudio 2015 and I want to publish it (eg give an exe or installer to somebody to use it on its PC). From VisualStudio there is possibility to click "publish" in solution explorer. The result files are:
-Application files (File folder)
-project.application (Application manifest)
-setup.exe (Application)
As far as I know "manifest" file should be some metadata, but I can execute that file and it gives me an installer (the same as setup.exe). After installing it runs an application (just like setup.exe). It makes me confused - what exactly project.application is? Can I delete it and use only setup.exe? What is the correct way of publishing an app? One last thing: why does the installer run installation on first execution and run an application on any other? I would expect to run installation any time (just like other software).
Thanks
It sounds like a ClickOnce application. See the following link for more information:
ClickOnce security and deployment
In a nutshell:
The installer copies the files to the users AppData and then runs the application.
There are also other options such as checking for updates from a network location or web address. Then when you run the application it checks for updates and uses the manifest to do an incremental update of the application files.

Access dynamic file in .NET CORE 2

I'm trying to figure out a way to deploy .NET Core project containing files that are acting as data storage. I'm using .csv files. I will be modifying these files, both manually and programmatically. This project could potentially be deployed to Windows, Linux, and Mac, so I don't know where these files should be located. I've attempted to make them embedded resources and access them via scoping to the assembly, but any changes to these files don't seem to be represented when accessing this way.
How would I go about achieving what I want?
The location to store data files like that varies between systems. For the most part, you're supposed to use environment variables to store data in a subfolder of the appdata folder on Windows or a subfolder of a user's home directory on Linux. (And probably OS X too, though I don't know that one)
Alternatively, you can write a program that is "portable" or doesn't need to be installed to run, and you can store your data files in the same folder your application is run from.

How do I publish a .NET application with OneClick publish through Visual Studio 2015?

I've been trying to research this the last couple of days and it doesn't seem like there is very good support for beginners. All video tutorials I find don't answer the questions I'm asking.
What I want:
I have an application I've written with .NET 4.6.1 in Visual Studio 2015 and I want to distribute an .exe that automatically checks if there are updates. It seems like this is exactly what OneClick is intended to do.
Where I'm at right now:
I want to publish to a shared drive among multiple people. It seems like I put that file path in the "Publishing Folder Location" which produces Setup.exe, MyApp.application, publish.htm, and Application Files. When you go to publish.htm there is an install button that downloads Setup.exe.
Where I'm stuck:
When you download the Setup.exe file onto your local machine and try running it gives an error. The details say it wasn't able to find the MyApp.application file. It seems that file is responsible for knowing what version of MyApp is currently installed on the users machine so that it can be compared to the download location (in my case the shared drive) to see if updates are available.
What am I missing? Do I misunderstand the purpose of OneClick publishing? Shouldn't users be able to visit the publish.htm once to get an .exe and that .exe is used to launch my application and look for updates first? I really appreciate any insight on this topic!
PS I've read over all the MSDN documentation, but it isn't user friendly to beginners in my opinion. Or maybe I'm just slow : )
You understand it exactly right, but when a user navigates to the html page, it downloads multiple files. The .exe, the .application and other supporting files.
You are correct in assuming ClickOnce is what you want. What I've found is the .net dependencies are very particular when using click once. You have to make sure each machine has the correct version of the framework and then they can use the htm site.
What I prefer doing is distributing the .application file to the users machine and just letting them run that. It will check for updates on the server every time it is ran and copy all the necessary decencies to the users Local directory.
You have to direct the users to the .application-File.
That one is responible for versioning (Updating) and executing your Application.
If you execute the .exe it will look for the .application-file to find the infos about the version, which should be installed/downloaded.
NOTE
Not all Browsers (in case of internet/intranet-deployment) support ClickOnce. But there are extensions for almost every browser

Setup Project and Access Permission

I created a setup project in VS2008. This setup copy some folders/files to the program files folder. Also, it adds some windows environment variables.
During the instalation, I am requested to confirm something in a UAC dialog.
This works fine, and all files are copied.
The problem begins when my program is running and I have to modify the a file´s content.
An exception is thrown, saying that I have no permission. Also, if I try to do the same operation in Windows Explorer => same problem.
My question is:
If I have the permission to install my software in program files folder, shouldn´t I be able to write in this folder as well?
Well, it seems that this is a general permission problem. By default normal users (and applications) cannot write to %PROGRAMFILES%. There are folders specially provided for application data storage such as ApplicationData
The reason the setup does install into program files is because this default behaviour of the Windows Installer. Check this link for more info on the Windows Installer and clickonce setup

Categories

Resources