+44(0)1908 545 770
YOUR EXPERT RPA PARTNER

Team up with our RPA strategy and tech specialists for maximum automation impact

Find out more
Harness the power of UiPath in your business.
WATCH NOW

Save money and spend more time on priority work.

Book consultation
READY, SET, AUTOMATE

Let's choose, design and deploy a process automation solution for your business.

Find out more
TRANSFORM YOUR BUSINESS

Let's analyse your business to discover opportunities for innovation and automation.

Find out more

Begin your business transformation journey

Book consultation
AUTOMATE EVERY FUNCTION

Automate where it matters most. Scale to solve challenges in every area

Find out more
GIVE EVERY TEAM THE TOOLS FOR SUCCESS

Equip people with user-friendly solutions that save time and make work easier

Find out more

Which business problem
can we solve first?

Book consultation
25 May 2019

How to create an automatic updater for an application using .net

Most of the automatic updaters require a FTP connection to pull the updates from the server and push it to the clients. Sometimes this FTP might create some security threats for the server and the organisation as a whole. In this article, we are going to see an alternative way of creating an automatic updater just by using a database.

Before getting started

This architecture contains the main application, updater application, and any database.

Step 01

Fetch the current version of the application installed in the system. The code snippet for retrieving the version is given below:

var versionInfo = FileVersionInfo.GetVersionInfo(pathToExe);

string version = versionInfo.ProductVersion;

Step 02

Retrieve the latest version number from the database and compare it with the installed version. If the database version number is the higher in comparison then proceed to open the automatic updater and close the main application. The code snippet is given below:

if (CurVer < newver)

{

Process.Start(PathofUpdater);

Application.Exit();

}

Step 03

The automatic updater will connect to the database and read the file content, file name, etc, from the blob field type and assign them in a dataset.

Iterate the dataset and write the file content and create them as a new file in the overwrite mode. The code snippet is given below:

connection = new SqlConnection(ConnectionString);

connection.Open();

command.Connection = connection;

command.CommandType = CommandType.StoredProcedure;

command.CommandText = StoredProcedureName;

param = new SqlParameter(“@IpValue1”, IpValue1);

param = new SqlParameter(“@IpValue2”, IpValue2);

param = new SqlParameter(“@IpValue3”, IpValue3);

param.Direction = ParameterDirection.Input;

param.DbType = DbType.String;

command.Parameters.Add(param);

adapter = new SqlDataAdapter(command);

adapter.Fill(ds);

connection.Close();

if (ds.Tables[0].Rows.Count > 0)

{

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

{

byte[] data = (byte[])ds.Tables[0].Rows[i][“file_content”];

File.WriteAllBytes(destpath + ds.Tables[0].Rows[i][“file_name”].ToString(), data);

}

}

Step 04

Update the registry values with the latest version, if needed.

Step 05 

The application should be converted into byte[] array and should be inserted into the database by using the below code snippet. It can be done through a separate application.

byte[] bytes = File.ReadAllBytes(FilePath);

connection = new SqlConnection(ConnectionString);

connection.Open();

command.Connection = connection;

command.CommandType = CommandType.StoredProcedure;

command.CommandText = StoredProcedureName;

param = new SqlParameter(“@IpValue1”, IpValue1);

param = new SqlParameter(“@IpValue2”, IpValue2);

param = new SqlParameter(“@IpValue3”, IpValue3);

param.Direction = ParameterDirection.Input;

param.DbType = DbType.String;

command.Parameters.Add(param);

cmd.ExecuteNonQuery();

Things to note…

  • The database field should be BLOB in database.
  • Ensure the newly created file replaces the previous file.
  • Make a note the system number and version number in separate table so that you can have a list of computers with installed version number.

Conclusion

In conclusion, this step-by-step guide informs you how to create an automatic updater using .net which enables a higher level of security through an efficient automatic process.

Synergy is brought to you by our Technical Experts at Velocity IT, it provides low-code developers a knowledge base of intelligent and creative solutions, built and implemented on real-time projects.

Need further technical advice or support on .NET or other low-code developments, get in-touch with one of our experts…