c#Visual Studio Project安装程序将文本框中的数据保存到文本文件中 [英] c# Visual Studio Project Installer save data from Textbox into Textfile

查看:152
本文介绍了c#Visual Studio Project安装程序将文本框中的数据保存到文本文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过大量研究,我不得不问你们,才能使我的项目最终运行.

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

我想将用户放入Visual Studio Project Installer的TextBox中的数据保存到文本文件中.我读过不同的文章,也是这篇文章: C#Visual Studio Project安装程序从文本框中检索数据 但是问题没有在那里回答,所以我想请您最终解决这个问题.

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.

请给我一个代码示例,其中用C#代码编写如何从文本框中获取此值并将其写入文本文件. 安装程序工具有库吗?

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.

提前感谢您的帮助!

Edit1:您需要指定"C#代码"的含义.如果您的意思是用C#编写的自定义操作,请说出您是指C#的自定义操作还是可执行文件:

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:

->我有一个用c#代码编写的大程序,我需要文本框中的数据.我想如果有可能将TextBox的数据写入并保存到.txt文件中.然后我可以在以后的大程序中阅读它.希望这能回答您的问题.

-> 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.

推荐答案

尽管可以执行自定义操作,但最简单的方法如下,并且不需要创建文本文件.

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. 使用安装项目的注册表视图创建注册表项和项目.查看-编辑器-注册表.您可以使用功能强大的HKCU Software Manufacture等密钥,并添加一些额外的文件夹.

  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.

通过右击键创建注册表项并添加新的字符串值.您可以将其称为MyEditString,并假设EDITA1是文本框属性的名称,并为其赋予值.方括号使它在安装时解析为实际值.

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 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.

否则,要编写C#自定义操作,请在此处进行演练:

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

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

其中显示了安装程序类示例,关键部分是添加自定义操作"部分,其中描述了如何以/mystuff = 形式传递文本以及您要安装的安装程序类代码说字符串myInput = Context.Parameters ["mystuff"];获得价值.

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= and the installer class code you'd say string myInput = Context.Parameters["mystuff"]; to get the value.

此方法的问题在于,通过自定义操作创建文本文件并非易事.您需要指定完整路径,并且要注意在Everyone安装中,您的代码正在使用系统帐户运行.

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.

这篇关于c#Visual Studio Project安装程序将文本框中的数据保存到文本文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆