Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I update a shared file on IIS and ASP.NET?
    text
    copied!<p>We're replacing an "old" web application (the original CodeCentral was written over 10 years ago, now running at <a href="http://cc.embarcadero.com" rel="nofollow noreferrer">http://cc.embarcadero.com</a> with over 12.7 million served) that uses a file based cache for serving downloads. The web application manages this file cache. </p> <p>The only complicated bit of using file-based downloads is updating a file that might be in use by another version. Back when I wrote the the original Delphi CGI version of CodeCentral, I vaguely recall being able to rename the existing file even though someone might be downloading it, writing the new file with the correct name, and eventually cleaning up the old file.</p> <p>However, I may be delusional, because that's not working with our current IIS 6 and ASP.NET 2.x or 3.x code. So, what we've done instead is this, which is quite kludgy but eventually works:</p> <pre><code>public static void FileCreate(Stream AStream, string AFileName, int AWaitInterval) { DateTime until = DateTime.Now.AddSeconds(AWaitInterval); bool written = false; while (!written &amp;&amp; (until &gt; DateTime.Now)) { try { using (FileStream fs = new FileStream(AFileName, FileMode.Create)) { CopyStream(AStream, fs); written = true; } } catch (IOException) { Thread.Sleep(500); } } } </code></pre> <p>I'm thinking we're missing something simple and there's got to be a better way to replace a file currently being downloaded via IIS and ASP.NET. Is there?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload