How to detect broken filestream downloadhttp://forums.asp.net/t/1784843.aspx/1?How+to+detect+broken+filestream+downloadSun, 25 Mar 2012 07:54:09 -040017848434897731http://forums.asp.net/p/1784843/4897731.aspx/1?How+to+detect+broken+filestream+downloadHow to detect broken filestream download <p>Code below is used to download backup from browser created by pg_dump in MVC2 application. If pg_dump crashes, incomplete file is downloaded without any notice.</p> <p>How to detect crash and send message to browser so that downloaded file is incomplete or OK? Maybe Exited event with jquery in browser can used as shown in code below.</p> <pre class="prettyprint">[Authorize] public class BackupController : ControllerBase { [AcceptVerbs(HttpVerbs.Get)] public FileStreamResult Backup() { var process = new Process(); process.StartInfo.Arguments = &quot;-ib -Z6 -Fc -h 45.878.78.76&quot;; process.StartInfo.FileName = &quot;c:\\Program Files\\PostgreSql\\9.1\\bin\\pg_dump.exe&quot;; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true;</pre> <pre class="prettyprint">&nbsp;&nbsp; process.StartInfo.RedirectStandardError = true; </pre> <pre class="prettyprint"> Server.ScriptTimeout = 8 * 60 * 60; // 8 hours process.EnableRaisingEvents = true; process.Exited += (sender, e) =&gt; { TempData["ExitCode"] = process.ExitCode; </pre> <pre class="prettyprint">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TempData["ErrorInfo"] = process.StandardError.ReadToEnd(); </pre> <pre class="prettyprint"> // todo: how to send and show exit code and error info in browser }; process.Start(); return new FileStreamResult(process.StandardOutput.BaseStream, "application/mybackup"); } }</pre> 2012-03-25T06:59:15-04:004897747http://forums.asp.net/p/1784843/4897747.aspx/1?Re+How+to+detect+broken+filestream+downloadRe: How to detect broken filestream download <p>because it takes that much time</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>kobruleht</h4> <span class="pln"></span><span class="typ">Server</span><span class="pun">.</span><span class="typ">ScriptTimeout</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">8</span><span class="pln"> </span><span class="pun">*</span><span class="pln"> </span><span class="lit">60</span><span class="pln"> </span><span class="pun">*</span><span class="pln"> </span><span class="lit">60</span><span class="pun">;</span><span class="pln"> </span><span class="com">// 8 hours</span><span class="pln"></span></blockquote> <p></p> <p>In my opinion, the best is to start the process and make it log to a file. Then read from the file( open file read with no lock) and show the ouptout to the user . ( You can do also browser refresh meta tag or ajax to poll the server for modifications)</p> <pre class="prettyprint"></pre> 2012-03-25T07:21:41-04:004897764http://forums.asp.net/p/1784843/4897764.aspx/1?Re+How+to+detect+broken+filestream+downloadRe: How to detect broken filestream download <p>I understand from this:</p> <p>1. Clicking in download link uses window.open to redirect file download to other window.</p> <p>2. In former window jquery ajax call periodically checks for Session[&quot;ExitCode&quot;] and if this appears in session data, shows this for user.</p> <p>Is this best solution ?</p> <p>process.StartInfo.RedirectStandardError = true causes deadlock so it cannot used.</p> <p><span face="Consolas" size="2" color="#008000" style="color:#008000; font-family:Consolas; font-size:small"><span face="Consolas" size="2" color="#008000" style="color:#008000; font-family:Consolas; font-size:small"><span face="Consolas" size="2" color="#008000" style="color:#008000; font-family:Consolas; font-size:small"></span></span></span></p> <p>&nbsp;</p> 2012-03-25T07:44:26-04:004897773http://forums.asp.net/p/1784843/4897773.aspx/1?Re+How+to+detect+broken+filestream+downloadRe: How to detect broken filestream download <p>Right.</p> 2012-03-25T07:54:09-04:00