<p>What is the best way to implement, from a web page a download action using asp.net 2.0?</p>

<p>Log files for a action are created in a directory called [Application Root]/Logs.  I have the full path and want to provide a button, that when clicked will download the log file from the IIS server to the users local pc.</p>

[{'answer_id': 37656, 'author': 'Martin', 'author_id': 770, 'author_profile': 'https://Stackoverflow.com/users/770', 'pm_score': 6, 'selected': True, 'text': '<p>Does this help:</p>\n\n<p><a href="http://www.west-wind.com/weblog/posts/76293.aspx" rel="noreferrer">http://www.west-wind.com/weblog/posts/76293.aspx</a></p>\n\n<pre><code>Response.ContentType = "application/octet-stream";\nResponse.AppendHeader("Content-Disposition","attachment; filename=logfile.txt");\nResponse.TransmitFile( Server.MapPath("~/logfile.txt") );\nResponse.End();\n</code></pre>\n\n<p>Response.TransmitFile is the accepted way of sending large files, instead of Response.WriteFile.</p>\n'}, {'answer_id': 2583641, 'author': 'BiLaL', 'author_id': 309856, 'author_profile': 'https://Stackoverflow.com/users/309856', 'pm_score': 4, 'selected': False, 'text': '<p><a href="http://forums.asp.net/p/1481083/3457332.aspx" rel="noreferrer">http://forums.asp.net/p/1481083/3457332.aspx</a></p>\n\n<pre><code>string filename = @"Specify the file path in the server over here....";\nFileInfo fileInfo = new FileInfo(filename);\n\nif (fileInfo.Exists)\n{\n   Response.Clear();\n   Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);\n   Response.AddHeader("Content-Length", fileInfo.Length.ToString());\n   Response.ContentType = "application/octet-stream";\n   Response.Flush();\n   Response.TransmitFile(fileInfo.FullName);\n   Response.End();\n}\n</code></pre>\n\n<p><br />\n<strong>Update:</strong></p>\n\n<p>The initial code</p>\n\n<pre><code>Response.AddHeader("Content-Disposition", "inline;attachment; filename=" + fileInfo.Name);\n</code></pre>\n\n<p>has "inline;attachment" i.e. two values for Content Disposition.</p>\n\n<p>Don\'t know when exactly it started, but in Firefox <strong>only</strong> the proper file name was not appearing. The file download box appears with the name of the webpage and its extension (<em>pagename.aspx</em>). After download, if you rename it back to the actual name; file opens successfully.</p>\n\n<p>As per <a href="https://www.iana.org/assignments/cont-disp/cont-disp.xhtml" rel="noreferrer">this page</a>, it operates on <strong>First Come First Served basis</strong>. Changing the value to <code>attachment</code> only solved the issue.</p>\n\n<p>PS: I am not sure if this is the best practice but the issue is resolved.</p>\n'}]
['https://Stackoverflow.com/questions/37650', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3416/']