Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Response.BinaryWrite file name Question.

Status
Not open for further replies.

PSFMIS

MIS
Feb 3, 2006
28
US
I'm using Response.BinaryWrite to display some files that are outside of my webfolder and do not have Read permissions with IIS.

My question is about the code below. When I open or save files using this code the files are always named BinDoc.asp which is the name of this file.

Is there a way I can specify the name of the file?


BinDoc.asp
Code:
   	   	Response.buffer = TRUE

   	Dim vntStream
   	Dim oMyObject
	Dim FileName
	Dim StoreFolder

	FileName = Request.QueryString("FileName")
	StoreFolder = Request.QueryString("StoreFolder")

	Dim CaseFileType

	CaseFileType = UCASE(Right(Request.QueryString("FileName"),3))

	Select Case CaseFileType

		Case "PDF" 'Adobe PDF
			Response.ContentType = "application/pdf"
		Case "DOC" 'Microsoft Word
			Response.ContentType = "application/msword"
		Case "XLS" 'Microsoft Excel
			Response.ContentType = "application/vnd.ms-excel"
		Case "PPT" 'Microsoft PowerPoint
			Response.ContentType = "application/ms-powerpoint"
		Case "GIF" 'GIF Image
			Response.ContentType = "image/gif"
		Case "JPG" 'JPEG Image
			Response.ContentType = "image/jpeg"
								
	End Select
			
   	Set oMyObject = Server.CreateObject("ASPBinFile.clsASPBinFile")
   	vntStream = oMyObject.readBinFile("c:\datastore\documents\"& StoreFolder &"\"& FileName)
  	Response.BinaryWrite(vntStream)
	
   	Set oMyObject = Nothing

   	Response.End
 
something like this:
Code:
Select Case CaseFileType

        Case "PDF" 'Adobe PDF
            Response.ContentType = "application/pdf"
[red]Response.AddHeader("Content-Disposition", attachment;filename="myfilename.pdf")[/red]
        Case "DOC" 'Microsoft Word
            Response.ContentType = "application/msword"
        Case "XLS" 'Microsoft Excel
            Response.ContentType = "application/vnd.ms-excel"
        Case "PPT" 'Microsoft PowerPoint
            Response.ContentType = "application/ms-powerpoint"
        Case "GIF" 'GIF Image
            Response.ContentType = "image/gif"
        Case "JPG" 'JPEG Image
            Response.ContentType = "image/jpeg"
                                
    End Select

similarly add the red line for others with the correct extension...

-DNG
 
Wow.. Thats pretty simple. I pass the filename through the link already so I just put that variable at the end of the red text.

Code:
Response.Addheader "Content-Disposition", "inline; filename=" & FileName

I left out the parentheses because I would get the error below with them in when right clicking and choosing open in new window.


Microsoft VBScript compilation error '800a0414'

Cannot use parentheses when calling a Sub

/folder/BinDocs.asp, line 53

Response.Addheader ("Content-Disposition", "inline; filename=" & FileName)
--------------------------------------------------------------------------------------^


Thanks,
-Aaron
 
you dont need the parentheses...just do

Response.Addheader "Content-Disposition", "inline; filename=" & FileName

and NOT

Response.Addheader ("Content-Disposition", "inline; filename=" & FileName)

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top