c# Visual Studio Project Installer save data from Textbox into Textfile

守給你的承諾、 提交于 2020-01-11 13:34:07

问题


After a lot of research I have to ask you guys in order to get my project finally running.

I want to save data which the user puts into a TextBox of the Visual Studio Project Installer to a text file. I have read different articles, also this one: C# Visual Studio Project Installer retrieve data from Textbox But the question was not answered there so I'm asking you to get this question finally solved.

And please give me a Code example where it is written in C# Code how to get this values from the textboxes and write it into a Textfile. Is there a libaray of the installer tool?

Please help me I'm despairing more and more with this installer.

Thanks in advance for your help!

Edit1: You need to specify what you mean by "C# code". If you mean a custom action written in C# then say whether you mean an C# custom action or executable:

-> I have a big program written in c# code where I need the data from the textboxes. I thougt if it would be possible to write and therefore save the data of the TextBox into a .txt file. Then I could read it later in my big programm. Hope this answers your question.


回答1:


If this is the installer that you are developing then Write a C# custom action and schedule it in install UI sequence. Use the property of the textbox to obtain its value.

But this can happen only on a button click or similar action by user.If you are looking for dynamic update then I am afraid that you will need to write custom bootstrapper UI as windows installer default UI doesn't support this.

Scheduling custom action in UI sequence

Authoring custom actions




回答2:


Although a custom action would do this, the simplest way to do this is as follows, and it does not require creating a text file.

  1. Create a registry key and item using the registry view of the setup project. View-Editor-Registry. You could use the exusting HKCU Software Manufacture etc key and add some extra folders.

  2. Create an registry item by righ-clicking the key and add a new string value. You could call it MyEditString, and give it the value [EDITA1] assuming EDITA1 is the name of the textbox property. The square brackets cause it to be resolved to the actual value at install time.

When that program requires the value it just reads that registry item.

Otherwise, to write a C# custom action there is a walkthrough here:

https://msdn.microsoft.com/en-us/library/9cdb5eda(v=vs.100).aspx

where it shows a installer class example, and the key part is the "To add a custom action" section where it describes how to pass the text in the form /mystuff=[EDITA1] and the installer class code you'd say string myInput = Context.Parameters["mystuff"]; to get the value.

The problem with this approach is that creating a text file from a custom action is non-trivial. You need to specify the full path, and be aware that in a Everyone install your code is running with the system account.

In general this type of configuration step is best done the first time your app is used. It sounds as if this file is going to be changed by the user anyway if it's user-configurable, so make it part of the application.



来源:https://stackoverflow.com/questions/47131830/c-sharp-visual-studio-project-installer-save-data-from-textbox-into-textfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!