dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Membersnaveensanagasetti
Padma
Matt M
Sivathanumalayan Rm K
Ranipriya
baskar
Ravi
gopal
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » .NET programming » Visual Studio

How to Create Setup file for .NET windows application?


Posted Date:     Category: Visual Studio    
Author: Member Level: Diamond    Points: 70


In this article I have explained about how to create set up file with MS Access Database, Uninstall option, etc. Each steps I have clearly explained in this article with screen shot. First step (create windows application) to last step Uninstall option all are covered in this article.



 


Description

Create windows application

First we need to create one windows application. Then we create set up file for that application.
Select File -> New -> Project in Visual Studio Standard tool bar.
image1


Give Name for your windows application
image2


Design side
I have design my form with one text box and one DataGridView look like this
image3


In this data grid view I have bind data from MS Access Database. And I use that text box for search records based on name.

Server Side
I have declare variables and connection details in the class

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Configuration;
using System.Diagnostics;

namespace WindowsSetup
{
public partial class Form1 : Form
{
//You can place your database "Data-directory/Databasefile" under your project bin/Debug folder
static string s=Application.StartupPath + "\\Data\\test.mdb";
static string constr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + s + ";";

OleDbConnection con=new OleDbConnection(constr);
OleDbCommand cmd=new OleDbCommand();
OleDbDataAdapter da=new OleDbDataAdapter();
DataTable dt=new DataTable();

If you want uninstall option for your set up file then write code to get Command Line argument like below.

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
//Below code is used to uninstall application

//Get Command Line Arguments
string[] arguments = Environment.GetCommandLineArgs();
foreach (string argument in arguments)
{
if (argument.Split('=')[0].ToLower() == "/u")
{
string guid = argument.Split('=')[1];
string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
ProcessStartInfo si = new ProcessStartInfo(path + "\\msiexec.exe", "/i " + guid);
Process.Start(si);
Close();
Application.Exit();
System.Environment.Exit(0);
}
}

//Load DataGridView first time when form load
refreshGrid();
}

void refreshGrid()
{
string query;
con.Open();
if(textBox1.Text=="")
{
query="select eno,empname,sal from emp";
}
else
{
query = "Select eno,empname,sal from emp where empname like '%" + textBox1.Text + "%'";
}
cmd=new OleDbCommand(query,con);
da = new OleDbDataAdapter(cmd);
dt.Clear();
da.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
//Refresh grid values when each text entered in textbox by user.
refreshGrid();
}
}

That's all we done create one windows application. Compile this application and run it. Output look like below.

output


How to create setup file for .Net Application?

Now we can create set up file for this application with MS Access database.
Go to File - > Add-> New project in the Existing opened Project Visual Studio screen.
image4


Then Select "Setup and Deployment" and right side select "Set up Project" (under visual studio installed templates) in the dialogue box. Give the name for your set up file.
image5


After enter name click Ok button. Screen look like below. Check it that set up file added in your solution explorer (right side)
image6


Now right click on the application folder select Add->Project Output.
image7


After select New pop up appear in that window select "Primary Ouput" Click Ok.
image8


How add MS Access database to the Set up file?

I have placed access database in my application "Data" directory so I need to create directory for same like this in application folder. Right Click of the application folder and choose Add - > New folder and name it for that folder "Data"
image9


Double click that "Data" folder in the application folder to open, now right click and choose Add->File
image10


After select new dialogue box is appear and ask for your database location. Select your database path and click ok in that dialogue box. After added it check your database attached in Application folder look like this.
image11


How to add Desktop Shortcut in setup file?

Select Application folder in File System and right click of the Primary Output file to create short cut for that file.
image12


Rename of that shortcut and cut that shortcut file
image13


After cut that shortcut go to File System (left side) user's desktop, double click that folder and open it and paste that shortcut
image14


If you want change the icon of short cut then select that short cut right click -> choose properties window. In that property window choose icon option to set icon for your desktop shortcut. Make sure if you want add icon in the short cut then you must add that icon in the application folder before.

How to create Shortcut in Programs menu during set up creation?

Select Application folder in File System and right click of the Primary Output file to create short cut
image12


Rename that shortcut same like above steps and Create one new folder in user's Program menu and paste that shortcut under that folder.
image15


How to create uninstall Shortcut in Programs menu?

Select Application folder in File System and right click of the Primary Output file to create short cut
image12


Rename that shortcut to "uninstall" same like above steps and Paste that shortcut under user's programs menu like this
image16


Select that uninstall short cut right click choose Properties.
image17


In that property window give Arguments value /u=[ProductCode]
.
image18


Now select set up file in solution explorer and build it
image19


In this example I have create project "D:\WindowsSetup" name. So now I go to my project location "D:\WindowsSetup" Set up file folder "Windows_Setup" is available in that project folder and set up file is available in this path "D:\WindowsSetup\Windows_Setup\Debug" folder.
image20


Just I double click that set up file to install in my system. After installation Shortcut for that application is created automatically in Desktop and Program files menu.


Desktop shortcut
image21


Program Menu Shortcut with uninstall option
image22


Source Code
Here i have attached source code, if you want source then download it and try to create set up file.

Conclusion:
I hope this article help to know about set up file creation using Visual Studio for .Net application.

Attachments
  • Source_code (43059-231231-WindowsSetup.rar)





  • Did you like this resource? Share it with your friends and show your love!


    Responses to "How to Create Setup file for .NET windows application?"
    Author: Jitendra Chandrakant More    14 Jul 2011Member Level: Silver   Points : 0
    I like it very much and will help me in creating the setup of my project.Thank you very much.


    Author: BHANU PRAKASH BYSANI    20 Jul 2011Member Level: Gold   Points : 1
    hi After building the project iam getting this error


    Error 1 Unrecoverable build error F:\WindowsFormsApplication1\Setup1\Setup1.vdproj Setup1

    and in debug folder a file is creating tmp file..

    plz help me in rectifying the error



    Author: Ravindran    20 Jul 2011Member Level: Diamond   Points : 1
    @BHANU

    Reason for your error may be version compatible problem or some Mergemod.dll not register please check this link

    http://support.microsoft.com/kb/329214/EN-US/




    Author: SonyMadhu    27 Aug 2011Member Level: Gold   Points : 1
    Hi Ravindran,


    This article is nice.
    Just i downloaded and followed your steps.I double click that set up file to install in my system. After installation,
    1.Icon with text 'h'
    2.Windowssetup
    3.WindowsSetUp.exe XmlConfiguration file
    4.Icon with 'DskShortcut'
    the above 1 to 3 are also created in Desktop.




    Regards,
    Madhu







    Author: Harsha    27 Aug 2011Member Level: Bronze   Points : 0
    It's help me so much in my project.. thank you


    Author: AMISH KUMAR    22 Nov 2011Member Level: Bronze   Points : 0
    its a very fantastic site to learn thanks alot


    Author: Sagar S pawar    07 Dec 2011Member Level: Gold   Points : 0
    its a very nice resource.
    I learn to add uninstall method in installer.



    Author: manikandan    13 Mar 2012Member Level: Bronze   Points : 0
    i got litral ans...thanks


    Guest Author: Uknees     19 Mar 2012
    Hi Jim, thanks for neltitg me know about this. The WordPress module seems to work fine with Safari, but the Joomla module doesn't. I'm going to look into it and will be back as soon as possible with the solution.


    Guest Author: balu     20 Aug 2012
    i go through the above process .. but i got error.. that i am receiving data from database ok.. when i am inserting data into emp table(in the application window after installation) it show error ..'operation must use an updatable quer'.. when i open .accdb (database) file in installation folder(c:\...) it shows that it is read only ...


    Author: Dinesh Kudale    22 Aug 2012Member Level: Silver   Points : 1
    First time, I am creating setup file after seen your screen shot.
    Really it is very useful to fresher / student like me who want to know that how to create set up file of own program.
    Again,really,really,really thanks.



    Author: Ravindran    22 Aug 2012Member Level: Diamond   Points : 0
    Balu make sure it is permission issue mostly it comes it windows7 OS. Make sure you have set sufficient permission to access that folder and database


    Author: Ravindran    22 Aug 2012Member Level: Diamond   Points : 0
    Thanks Dinesh


    Author: siraj    30 Aug 2012Member Level: Bronze   Points : 0
    superbb


    Guest Author: Archal Gharat     18 Oct 2012
    Thanks a lot! I have successfully created the setup file. But the uninstall in Program menu again opens my application instead of uninstalling the application from my system. Can u help me??


    Author: Ravindran    29 Oct 2012Member Level: Diamond   Points : 3
    Archal make sure your write this code in form load


    private void Form1_Load(object sender, EventArgs e)
    {
    //Below code is used to uninstall application

    //Get Command Line Arguments
    string[] arguments = Environment.GetCommandLineArgs();
    foreach (string argument in arguments)
    {
    if (argument.Split('=')[0].ToLower() == "/u")
    {
    string guid = argument.Split('=')[1];
    string path = Environment.GetFolderPath(Environment.SpecialFolder.System);
    ProcessStartInfo si = new ProcessStartInfo(path + "\\msiexec.exe", "/i " + guid);
    Process.Start(si);
    Close();
    Application.Exit();
    System.Environment.Exit(0);
    }
    }

    //Load DataGridView first time when form load
    refreshGrid();
    }



    Guest Author: Abhishek     19 Dec 2012
    Nice Sir but how i make .exe using Registration key with our own.


    Guest Author: Meena Rawat     14 Feb 2013
    hey
    when i install setup then it is not working ...
    don't know what would be happen..
    please suggest me what i have to do ... plzzz



    Author: Murugesan.P    21 Feb 2013Member Level: Bronze   Points : 0
    it is very use ful.....but I m using SQL SERVER

    I want the same Steps for SQL SERVER 2008(.mdf file)


    Thank u,
    MURUGESAN.P



    Guest Author: smitha     23 Mar 2013
    Very well explained..This is exactly what i wanted..thankx for saving my time..


    Feedbacks      

    Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Visual Studio
    Previous Resource: Code Shortcuts in Visual Studio 2010
    Return to Resources
    Post New Resource
    Category: Visual Studio


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Setup file creation  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.