This is a winforms vb.net application. Because of some limitations I am not able to use the built in clickOnce updating available in VS. So to handle updates for my application i have wrote an update app. which downloads an email attachment and processes it. All works great up to and including deleting the old files from the applications install folder and then moving the updated files to that folder.
But the new files seem to not have any effect on the application at all. Just for testing I placed a MessageBox.Show in the applications Form Load event.. The app shows the messagebox in VS when I debug. As well as when I run the app from the bin folder.. When my updater app does the copying the files are there but no dice nothing is changed and no message box shows when the app loads. Further investigating the problem I manually deleted the files that are to be replaced in the application folder and then unzipped the contents of the update zip file to that folder.. Started App and now a message box shows.. If I copy the files for the app directly from the bin folder to the app folder it shows as well.
This leads me to believe that there is something going on behind the scene in the below function that I am not catching. Any ideas why this is failing???
Function ApplyUpdates(ByVal c As Integer, ByVal e As List(Of MessagePart))
Dim xxxxState As Boolean = False
Dim _path As String = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) + "\XXXX\UpdateFiles\"
Dim d As Integer = 20
xxxxState = isProcessRunning("xxxx")
If xxxxState = True Then
KillxxxxTask()
End If
For Each _S In System.IO.Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) + "XXXX\UpdateFiles")
System.IO.File.Delete(_S)
Next
For Each att In e
Dim y As Boolean = UnZip(att.FileName)
Next
For Each f In System.IO.Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) + "\XXXX\UpdateFiles")
Dim y As String = Path.GetExtension(f)
Dim _fNM As String = Path.GetFileNameWithoutExtension(f)
If y.Contains("ex0") Then
My.Computer.FileSystem.RenameFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) + "\XXXX\UpdateFiles" + "\" + _fNM + y, _fNM + "." + "exe")
f = f.Replace("ex0", "exe")
End If
If y.Contains("dl0") Then
My.Computer.FileSystem.RenameFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) + "\XXXX\UpdateFiles" + "\" + _fNM + y, _fNM + "." + "dll")
f = f.Replace("dl0", "dll")
End If
updating(d, "Copying File : " + f)
d += 10
Dim fName As String = Path.GetFileName(f)
Next
For Each S In System.IO.Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) + "\XXXX\UpdateFiles")
Dim _ofile As String = Path.GetFileName(S)
If File.Exists("C:\XXXX\" + _ofile) Then
File.Delete("C:\XXXX\" + _ofile)
End If
' File.Copy(S, "C:\XXXX\" + _ofile, True)
Next
For Each S In System.IO.Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) + "\XXXX\UpdateFiles")
Dim _ofile As String = Path.GetFileName(S)
File.Move(S, "C:\XXXX\" + _ofile)
Next
updating(100, "Update Completed")
Return Nothing
End Function
This sounds an awful lot like Windows File virtualization.
Search for the file in
C:\Documents and Settings\<userName>\Application Dataand subfolders, I suspect you’ll find them in there.Windows does this to protect your program from itself if you don’t include an app.manifest in your project. Windows will assume your application is an old, legacy application that is not UAC aware unless it has an app.manifest. To prevent your application from crashing from denied file access, it allows the file operation to be performed, but instead secretly maps the file operation to a safe, local folder.
Just add an app.Manifest: Project Add -> New Item -> Application Manifest File
That should do it. You may find that you need to request an elevated permission, but the details are all in the app.manifest file.
For details on File Virtualization, have a look at this explanation. It’s a big article, but if you Ctrl-Find ‘Virtualization process’ it will take you to the relevant section.
See This MSDN article for more details on the app.manifest.