1
I have an application that checks and downloads a file as soon as it runs through the Window_Loaded
.
Here is the method that performs this task:
XmlDocument doc = new XmlDocument();
doc.Load("http://www.meusite.com.br/dirdaaplicacao/arquivoXML.xml");
XmlNode node = doc.DocumentElement.SelectSingleNode("/Application/Version");
XmlNode node1 = doc.DocumentElement.SelectSingleNode("/Application/ZipFile");
string version = node.InnerText;
string zipfile = node1.InnerText;
string End = (@"\\servidor\wwwroot\meusite.com.br\dirdaaplicacao\");
string file = (End + zipfile);
string versionAssembly = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
if (Convert.ToDouble(version) <= Convert.ToDouble(versionAssembly))
{
MessageBox.Show("Sistema Atualizado " + version);
}
else
{
ZipFile zipFile = ZipFile.Read(file);
{
foreach (ZipEntry zipEntry in zipFile)
{
zipEntry.Extract(@"C:\IASD\Diretorio\Temp", ExtractExistingFileAction.OverwriteSilently);
}
}
MessageBox.Show("Atualizando o sistema! A aplicação será reiniciada! Versão: " + version);
The executable and the installation files of this application are in c:\IASD\Diretorio
and the files that are uncompressed will be in c:\IASD\Diretorio\Temp
.
I created the Temp folder because it is not possible to download to the application directory a file that is being used (such as the application’s own .exe) even using the Ionic.zip API.
zipEntry.Extract(@"C:\IASD\Diretorio", ExtractExistingFileAction.OverwriteSilently);
The error that is reported refers to The file 'nome_do_arquivo' already exists.
Then I would like a help to this problem:
At the end of the extract to the Temp folder I call a DOS command which closes the application, moves the files from the folder c:\IASD\Diretorio\Temp
to the folder c:\IASD\Diretorio
and restarts the application.
Note: I tested the above method running directly from Visual Studio and it worked perfectly.
If you can help with these commands in DOS.
How do I move a file that is running with the application open? I thought in a cmd command that as soon as the file is downloaded in temp folder, it would close the application, copy the files and then restart the application.
– Paulo Romeiro