I have an application that checks and downloads a file as soon as it runs through Window_Loaded
.
Here is the method that accomplishes 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 installation files for this application are 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 a file that is being used (such as the application's own .exe) to the application directory, 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.
So I'd like some help with this problem:
At the end of the extraction into the Temp folder I call a DOS command that closes the application, moves the files from the c:\IASD\Diretorio\Temp
folder to the c:\IASD\Diretorio
folder, and restarts the application.
Note: I tested the above method by running directly from Visual Studio and it worked perfectly.
If you can help with these DOS commands.