Must click twice to get correct output from GetLastWriteTime

I have a button click that fires a function that runs a .bat file. The bat file updates a zip. The web page has a label that displays the timestamp of that zip file. The problem is the button has to be clicked twice to get the correct time displayed. The first click _will run everything...if i look at the file on the server, it has the correct time...but the label doesn't show that until i click the button again.
<asp:button id=cra onclick=cra_Click runat="server" Text="Repackage"></asp:button>

    Sub cra_Click(ByVal sender As Object, ByVal e As EventArgs)
    End Sub

Function DoPackage(ByVal pack)
      ' Get the full file path
      Dim strFilePath As String = Server.MapPath("\MyPath\") & pack & ".bat"
      ' Create the ProcessInfo object
      Dim psi As New System.Diagnostics.ProcessStartInfo("cmd.exe")
      psi.UseShellExecute = False
      psi.RedirectStandardOutput = False
      psi.RedirectStandardInput = True
      psi.RedirectStandardError = True
      psi.WorkingDirectory = Server.MapPath("\MyPath\")
      ' Start the process
      Dim proc As System.Diagnostics.Process = System.Diagnostics.Process.Start(psi)
      ' Open the batch file for reading
      Dim strm As System.IO.StreamReader = System.IO.File.OpenText(strFilePath)
      ' Attach the output for reading
      'Dim sOut As System.IO.StreamReader = proc.StandardOutput
      ' Attach the in for writing
      Dim sIn As System.IO.StreamWriter = proc.StandardInput
      ' Write each line of the batch file to standard input
      While strm.Peek() <> -1
      End While
      ' Exit CMD.EXE
      Dim stEchoFmt As String = "# {0} run successfully. Exiting"
      sIn.WriteLine([String].Format(stEchoFmt, strFilePath))
      ' Close the process
      ' Close the io Streams;
End Function

Function WritePackLabels()
      If (System.IO.File.Exists(Server.MapPath("\MyPath\"))) Then
      lbmyFile.Text = System.IO.File.GetLastWriteTime(Server.MapPath("\MyPath\")).ToString()
      End If
End Function
Who is Participating?
raterusConnect With a Mentor Commented:
I think you need to "WaitForExit" on your Process, it's demonstrated here.

   Private Sub btnWaitForExit_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) _
      Handles btnWaitForExit.Click
      ' create a new process
      Dim myProcess As Process = _
      ' wait until it exits
      ' display results
      MessageBox.Show("Notepad was closed at: " & _
         myProcess.ExitTime & "." & _
         System.Environment.NewLine & "Exit Code: " & _
   End Sub
Try setting your autopostback = true for your button
juststeveAuthor Commented:
where would I set that?
?? buttons are always "autopostback", I don't think that is his problem.  It almost seems like the file doesn't exist when the time comes to update the label.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.