|
-
Dec 25th, 2006, 04:55 PM
#1
Thread Starter
Frenzied Member
Load files
Hi,
Im new to asp.net.I need to load several files from a web site.
My type of files are ppt, doc, xls files. I have made a search on the forum and thanks to Menhdak I found this
VB Code:
if System.IO.File.Exists(Server.MapPath("createdfiles/woof.txt")) Then
Dim TargetFile As New System.IO.FileInfo(Server.MapPath("createdfiles/woof.txt"))
' clear the current output content from the buffer
Response.Clear()
' add the header that specifies the default filename for the Download/
' SaveAs dialog
Response.AddHeader("Content-Disposition", "attachment; filename=" + _
TargetFile.Name)
' add the header that specifies the file size, so that the browser
' can show the download progress
Response.AddHeader("Content-Length", TargetFile.Length.ToString())
' specify that the response is a stream that cannot be read by the
' client and must be downloaded
Response.ContentType = "application/octet-stream"
' send the file stream to the client
Response.WriteFile(TargetFile.FullName)
' stop the execution of this page
Response.End()
End If
I replaced "createdfiles/woof.txt" and put in "mytext.doc" but this does not work. At the moment my file is in the bin. Obviously later on it will be on the server. can someone please help me with this. This is the first time Im loading a webs site. Also pls tell where i put the file and how to set its path in the code. Many many thanks
Many thanks
Last edited by angelica; Dec 25th, 2006 at 05:40 PM.
-
Dec 28th, 2006, 05:24 AM
#2
Re: Load files
You need to specify the path to the file. If you've just got
Code:
if System.IO.File.Exists(Server.MapPath("mytext.doc")) Then
Then it will look for mytext.doc in the root folder of the web application.
Therefore if your document is in your bin folder then you need to specify so
Code:
if System.IO.File.Exists(Server.MapPath("bin/mytext.doc")) Then
However you should create a folder in your project and place the files in there just to keep everything nice and separate.
-
Dec 28th, 2006, 06:05 AM
#3
Re: Load files
It's best not to place such files in a bin folder. Have a separate folder in your application's virtual directory just for your 'downloadable' files.
-
Dec 28th, 2006, 12:58 PM
#4
Thread Starter
Frenzied Member
Re: Load files[resolved]
ok, sorted out many thanks to both Fishcake and Menhak who's always there to help. cheers
Last edited by angelica; Dec 29th, 2006 at 04:51 AM.
-
Dec 28th, 2006, 12:58 PM
#5
Thread Starter
Frenzied Member
Re: Load files [RESOLVED]
ok, sorted out many thanks to both Fishcake and Menhak who's always there to help. cheers
-
Dec 28th, 2006, 07:19 PM
#6
Re: Load files
You're welcome. You're welcome. Small things, you learn.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|