Re: Access Denied

Tech-Archive recommends: Speed Up your PC by fixing your registry



Bruce, I guess you have got it wrong. What I am trying to do is allow
users to DOWNLOAD a file from a directory that resides on the server so
that they can SAVE that file on their local machine.


bruce barker wrote:
webclient is used to read a file from the web. you are asking it to
download from a file path which is not normally allowed.

i believe you are trying to read the file and send to the browser, which
would be:


Response.TransmitFile(
Path.Combine(
Server.MapPath("Folder1\MyDir")
,strFileName));

you will still need to set the content-type header.

-- bruce (sqlwork.com)


rn5a@xxxxxxxxxxxxxx wrote:
I have a ASPX page which has a ListBox & a Button. The ListBox lists
all the files & directories existing in a directory on the server. I
want to give users the option to download files from the server.

When a user selects a file from the ListBox & clicks the button to
download the selected file, I am getting the following error:

Access to the path 'c:\inetpub\wwwroot\Folder1\MyDir' is denied.

The directories & files that the ListBox lists reside in the 'MyDir'
directory. This is the OnClick event function of the button:

<%@ Import Namespace="System.Net" %>

Sub DwnldFile(obj As Object, ea As EventArgs)
Dim strFileName As String
Dim wClient As New WebClient

strFileName = Request.Form("lstFD")
wClient.DownloadFile(Server.MapPath("Folder1\MyDir"), strFileName)
End Sub

I have gone through a no. of posts to resolve this issue but haven't
had any luck so far.

Can someone please tell me where I could be going wrong?


.


Quantcast