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

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.

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

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

Related

Approach to follow for undo all changes been done in desktop.ini and also on uninstall of C#.NET application

I have my software been developed in .net in C# and i am modifying desktop.ini file from that software. I am successfully been able to update desktop.ini. But i have one question like what approach should i follow to keep information of desktop.ini which was there previously like should i store information in database or something like that?
And i wanted to reupdate my information of desktop.ini, i.e. information which was stored previously on uninstallation of my software.
I would really appreciate if someone could explain me what approach should we follow for this.
Thanks
Dharmen
In the specific case of ini files, the answer is to use a tool that supports the standard Windows Installer method of managing ini file content - the IniFile table and the WriteIniValues and RemoveIniValues standard actions, then you don't need to do anything. VS setup projects don't support this.
To code it yourself you'd just need to remember what sections and values you added, then remove them at uninstall time with an uninstall custom action. That's basically a development question about where to store the values so you can retrieve them to take out of the ini file at uninstall time. I don't know if that's much of an answer, but it's basically about coding a scheme to remember what you added or removed and then restoring those section values at uninstall time.
You should also have a rollback custom action to remove them in case the install runs your custom action to alter the ini file and then fails.

Edit Windows Context Menu in the C#

I would like a particular type of file (eg. Namefile.ext2) read all the names preceded by a #
Sample contents of the file:
#nameone
#nametwo
#namethree
When I click the right mouse button on the ext2 file extension beyond the standard options (like: open, properties, etc ...) I would like to be:
contents of the file > nameone
nametwo
namethree
Then, select the item (eg. nameone) pass this parameter to my program running in the background / or services
Do you need to modify the registry somehow? I will be grateful for tips on how to achieve the desired effect.
What you are asking about is called 'shell extension'. Basically it requires some knowledge of COM objects programming, but .NET made things a bit easier in that matter.
Shortly: you have to develop a piece of code which will reads the file and generates menu items dynamically (which may be tricky but possible). That code needs to be registered in the system as COM object.
Before it starts working you have to associate file extension with COM object you created.
Perhaps this article can explaint it a bit more:
http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus

Getting the name in name textbox of a MSI Installer

I have a question:
I created a project and created a MSI to install my software. When i install it, when it asks me for the key, on the top there's a textbox which asks for you name. I need to take that name and put it in a .txt file. Is there any way to do it? I've read that i could maybe use a DLL, but to be honest, i'm still too noob in c++, and i'm REALLY running out of time. Is there a way to do it?
If you don't know much about custom actions in setup projects there is no quick answer. Basically, if you can write the code to write that name into the text file you're half way there. Then you need a custom action in which you pass the USERNAME property in the CustomActionData field of the custom action (hit f4 to see the properties window of a custom action). This might help:
https://www.simple-talk.com/dotnet/visual-studio/visual-studio-setup---projects-and-custom-actions/
and use [USERNAME] in the CustomActionData because USERNAME is the name of the property in that dialog and the square brackets cause it to be resolved to the actual entered string.

c# help needed for application update

Hello guys I think the question i asked in the previous post is unclear OK fine. i am explaining in brief.
for example.
I have a form where i have placed one textbox and command button.
I have fired a event when i click the button the text under the textbox change to "hello" ok fine.
what is my problem is..
the application is created and I published ok.
After some week I thought I want to update my application. where in the place of "hello" I want "hi". I know that we can compile the whole project and publish it.
but I don't want my whole application to be updated.
for example.
What antivirus company do they have a definition file where they only update the definition file not the whole application. after the update it applies to whole application.
I want my application also to do same process like antivirus company do.
You should read that "Hello" from a content file (XML). Then you can just push out the new file.
Use a configuration file. You can add an application.config (or if you're developing a web app, web.config) file to your primary project. Within this configuration file, you can define AppSettings (which are built-in, usually simple and atomic string or number fields that the application will need), ConnectionStrings (which specifically provide information applications will need to connect to a database), or custom configuration sections (used for more complex, related sets of data that are loaded into custom classes you define, such as a basic company profile). Within your code, you access AppSettings by using the static ConfigurationManager.Appsettings[] collection; you tell it the name of the setting you defined in the file, and it returns the value (or null, if it can't find the setting you defined).
Related, but different, is the use of Resource files. Resource files usually contain a dictionary of location-specific data used by the UI, such as text strings, icons and images. Actual resources can be compiled into one big file, or resource files can be a list of paths and filenames to the actual resources. You can use resource files to create different "skins" for your application to be used by different companies by referencing images to use for UI elements, or to translate labels and other text on your application's UI. Resource files are accessed through a ResourceManager; you tell it where the resource file is, and it will load the information into a similar "dictionary"; you then tell it the name of the resource and you get the resource back.
For your specific question, I'll answer the same thing as Henk. But, I think that your real question is "How I do create patch in .NET".
You can check this link:
How can I patch .NET assemblies?
You could design your application to use plugins. This way you only have to update a plugin and not the whole application.
if you want to create a patch for asp.net application , first of all , you have to deploy your project with Web Deployment Project.
then choose Create a separate assembly for each page and control output in output assemblies tab and re-build your solution .
the result of deployment is bunch of DLL which mapped to each page or control.
Now if you changed one page's data (in code behind) , you need to deploy your project again but in this case you can just upload the changed dll file.

How can I make an application open when a user double clicks on its associated file?

I am creating an application that uses a certain file format as its data source. I want this application to open whenever the user double clicks on this file, like how MS Word will open when a user double clicks on a Word document. How do I accomplish this? Also how would I populate the data fields using the file that the user selected. Would I use args[] from the program.cs class? I am using c# to code this application.
N.B. I want this association to be made when the application is installed on the host machine without the user doing anything.
FIRST, you need to set up file association, so that your file type is associated with your application and opening the file type will run your application.
You can do the file association programatically, there is some detail here as mentioned:
http://www.codeproject.com/KB/dotnet/System_File_Association.aspx
You can also do it via your Setup project for you application if you have one. This is an easier path for "newbies". Details for using visual studio to get the setup project to add the file association and also set the icon for the file are here:
http://www.dreamincode.net/forums/topic/58005-file-associations-in-visual-studio/
Otherwise if you use InnoSetup, Wix etc then I suppose you could just see instructions for those installers to create the association for you.
SECOND, you need to have your application accept command line arguments. The opened file(s) is(are) passed as a command line argument(s). You need to process the arguments to get the file path/name(s) and open the given file(s). There is a nice description of this here with code:
C# Command Line arguments problem in Release build
In your case, rather than MessageBox.Show(s) in the form shown handler, you would call your bespoke argument parsing method.
For a simple application which only accepts files names to open as arguments, this could be as simple as
foreach (string filePathName in Args)
DoNamedFileOpen(filePathName);
Your code can also have a method that might extract from the file the values for the datafields you are interested in etc.
This is a nice simple approach to the issue of have file associations set on installation of your application, with icons, and having your application handle the opening of those files.
Of course, there are plenty of other options, like run-time file association (asking the user if they want the association), detecting "broken" associations, etc.
This question is a long time here but I hope this is useful for new searches
See this. Or this if you want API information.
ClickOnce supports file associations as of .NET 3.5 SP1, too. In the project's properties, switch to the Publish tab and click the Options button. There's a File Associations section in that dialog that allows you to specify file extensions, descriptions and custom icons.
First, you have to associate the filetype extention with your executeable. On Windows you do this via the registry (search "filetype association windows"). In this question you find some interesting hints: Filetype association with application (C#) Script to associate an extension to a program
Your program has to react on the command line arguments or parameters. In Java, it is indeed the string array of the main method. I would gess, it's the same in C#.
If you don't need to do it pro programatically, right click on the icon, click open with ..., then select 'always use this program ...'.
This is something usually handled by your setup program .. I've used INNO setup for example, and it's trivially simple to arrange for it to adjust user's registry to launch your app when associated file extension is double clicked/opened. It'll even take care of MIME types for you as well as clearing these things on uninstall, which is a very nice thing to do
I managed to solve this issue. I used WIX to create an install file and asked it to associate the file with the application when it installs.

Categories

Resources