[thelist] .NET file downloader: access denied (still)
Joel D Canfield
joel at streamliine.com
Thu Aug 9 09:58:44 CDT 2007
Crystal Tech says the permissions are correct, and the problem must be
in the code. Any thoughts on why the code below (it's the entire page)
would cause the error "Access to the path "D:\inetpub\spinhead\test" is
denied" in reference to this line?
sourceFile = IO.File.Open(fullpath, IO.FileMode.Open)
The link (first line in the body) works just fine. Well, in IE, it opens
the file in an instance of Excel in the browser which is what I'd
expect.
=========================
<%@ Page Language="VB" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub BtnDownloadManual_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim path As IO.Path
Dim fullpath = path.GetFullPath(txtFilePath.Text)
Dim name = txtFileName.Text
Dim ext = path.GetExtension(fullpath)
Dim type As String = ""
If Not IsDBNull(ext) Then
ext = LCase(ext)
End If
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
type = "Application/x-msexcel"
Dim sourceFile As IO.FileStream
sourceFile = IO.File.Open(fullpath, IO.FileMode.Open)
Dim getContent(sourceFile.Length) As Byte
sourceFile.Read(getContent, 0, sourceFile.Length)
sourceFile.Close()
Response.AddHeader("content-disposition", "attachment;
filename=" + name)
If type <> "" Then
Response.ContentType = type
End If
Response.BinaryWrite(getContent)
Response.End()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Force Download</title>
</head>
<body>
<p><a href="joel.csv">plain link to joel.csv</a></p>
<form id="DownloadForm" runat="server">
<div>
<asp:TextBox id="txtFilePath" Columns="24" Runat="Server"
Visible="True" value="D:\inetpub\spinhead\test" />
<asp:textbox id="txtFileName" runat="Server" columns="24"
value="joel.csv" visible="True" /><br />
<asp:Button id="BtnDownloadManual" style="font-family: Verdana;
font-size:7pt" Text="Download Orders" OnClick="BtnDownloadManual_Click"
runat="server" />
</div>
</form>
</body>
</html>
More information about the thelist
mailing list