Deleting a client file after TransmitFile back to clienthttp://forums.asp.net/t/1789961.aspx/1?Deleting+a+client+file+after+TransmitFile+back+to+clientFri, 06 Apr 2012 14:34:50 -040017899614919498http://forums.asp.net/p/1789961/4919498.aspx/1?Deleting+a+client+file+after+TransmitFile+back+to+clientDeleting a client file after TransmitFile back to client <p>I'm trying to write a webpage that processes a clients file and then returns the file to the client. <br> When the file processing is completed a completion message is output to the clients browser and a <br> button is provided for the client to request the processed file.</p> <p>The following sub sends the file back to the client:</p> <p>&nbsp;&nbsp;<em> Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles ButtonSendClientFile.Click</em></p> <p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim attachName As String = &quot;attachment; filename= &quot; &amp; Label1Copyname.Text</em><br> <em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim appPath As String = Request.PhysicalApplicationPath</em><br> <em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim saveDir As String = &quot;ReturnToClientFiles\&quot;</em><br> <em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim fileName As String = Label1Copyname.Text ' Get the name of the file to upload.</em><br> <em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim savePath As String = appPath &#43; saveDir &#43; fileName</em></p> <p><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.ContentType = &quot;text/plain&quot;</em><br> <em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.AppendHeader(&quot;Content-Disposition&quot;, attachName)</em><br> <em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.TransmitFile(savePath)</em><br> <em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.End()</em><br> <em>&nbsp;&nbsp;&nbsp; End Sub</em></p> <p>The next thing I need to do is remove the clients file from my server folder &quot;<em>ReturnToClientFiles</em>&quot;<br> If I add the line:</p> <p>My.Computer.FileSystem.DeleteFile(savePath)</p> <p>nothing happens, and wherever I place it - no result (except errors).</p> <p>How do I achieve wiping the file after sending to client on a single button click event?</p> 2012-04-06T11:16:07-04:004919790http://forums.asp.net/p/1789961/4919790.aspx/1?Re+Deleting+a+client+file+after+TransmitFile+back+to+clientRe: Deleting a client file after TransmitFile back to client <p>Try this:</p> <pre class="lang-cs prettyprint"><pre class="prettyprint">Response.TransmitFile(savePath); Response.Flush(); File.Delete(savePath); Response.End();</pre></pre></pre> 2012-04-06T14:34:50-04:00