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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Powerpoint link in ASP

Status
Not open for further replies.

anikanchan

Programmer
Jul 18, 2005
11
US
Hey guys,

I am having problems with Powerpoint links from my ASP page. The ppt files are saved on the server and link is dynamically placed on ASP pages depending on the search criteria.

When I point my mouse to the link it gives correct filename (example: 38275[4].4728819444Tempest DIB VQ Baseline) but when I open it, it gives me blank Powerpoint screen. Even saving does not help. The saved file is empty and size it shows is 0kb. In the same code, if I have links to a doc or pdf files, it works fine.

Any suggestions/comments/advise?

Thanks,

Anikanchan
 
can you show us the actual link that you are using...are you using Server.MapPath(filename)

-DNG
 
This is where link is being placed on the asp page.......
<tr>
<td>
<table cellspacing="0" border="0" cellpadding="0" width="100%">
<tr>
<td class="InputLabel" colspan="2"></td>
</tr>
<%
If IsObject(oRsAttachments) Then

do until oRsAttachments.EOF

If oRsAttachments("AttachmentDesc") = "Original Report" Then
mInternalName = oRsAttachments("InternalName")
End If

%>
<tr>

<% ' IA 4-6-04 added the statement - 'and FinalApproval = "0"
' IA 6-17-04 modifed code to not open the file directly.

If sApproving = "1" and FinalApproval = "0" then
If Not objFs.FileExists(sSubmittedPath + "\" + oRsAttachments("InternalName")) Then
sFileNotFound = "Attachment has not been scanned yet. Please contact Mary Osborn"
End If
%>
<td nowrap valign="top"><a href="\erdb\open_file.asp?filename=<%=escape(oRsAttachments("InternalName"))%>&approved=0"><%=oRsAttachments("OriginalName")%></a></td>
<td><%=sFileNotFound%></td>
<%Else
If Not objFs.FileExists(sAttachmentPath + "\" + oRsAttachments("InternalName")) Then
sFileNotFound = "Attachment has not been scanned yet. Please contact Mary Osborn"
End If
%>
<td nowrap valign="top"><a href="\erdb\open_file.asp?filename=<%=escape(oRsAttachments("InternalName"))%>&approved=1"><%=oRsAttachments("OriginalName")%></a></td>
<td><%=sFileNotFound%></td>
<%End If%>
<td width="12">&nbsp;</td>
<td valign="top"><%=oRsAttachments("AttachmentDesc")%></td>
</tr>
<tr>
<td colspan=3 height="4">&nbsp;</td>
</tr>
<%
oRsAttachments.MoveNext
Loop
End If
%>
</table>
</td>
</tr>


and this is openfile.asp page.............


<%

' call downloadFile(replace(replace(Request("file"),"\",""),"/",""))

dim filename
dim approved

filename = unescape(request("filename"))
approved = request("approved")
if approved = "1" then
filename = "\erdb\documents\HdDocRepository" & "\" & filename
else
filename = "\erdb\documents\HdSubmittedDocs" & "\" & filename
end if

response.write filename
call downloadFile(filename)

'call downloadFile(replace(replace(filename,"\",""),"/",""))

function AddHeaders(strFile)
dim strFileType
dim ContentType

strFileType = lcase(Right(strFile, 4))

Select Case strFileType
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
Case ".rtf"
ContentType = "application/rtf"
Case ".pdf"
ContentType = "application/pdf"
'Added on 12/01/2005 -- Anikanchan
Case ".ppt"
ContentType ="application/ms-powerpoint"
Case Else
'Handle All Files
ContentType = "application/octet-stream"
End Select

AddHeaders = ContentType
end function


Function downloadFile(strFile)
' make sure you are on the latest MDAC version for this to work
' -------------------------------------------------------------

'get full path of specified file
'strFilename = server.MapPath(strFile)
strFilename = FxPath(strFile)

'response.write strFilename

'clear the buffer
Response.Buffer = True
Response.Clear

'create stream
Set s = Server.CreateObject("ADODB.Stream")
s.Open

' Set as binary
s.Type = 1

' load in the file
on error resume next

' check the file exists
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
Response.End
end if

' get length of file
Set f = fso.GetFile(strFilename)
intFilelength = f.size

s.LoadFromFile(strFilename)
if err then
Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
Response.End
end if

' send the headers to the users browser
Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
' Response.ContentType = AddHeaders(strFilename)
Response.ContentType = "application/octet-stream"

' output the file to the browser
Response.BinaryWrite s.Read
Response.Flush

' tidy up
s.Close
Set s = Nothing
End Function

function FxPath(path)
if instr(path,",") then
FxPath = replace(path,",","%2C")
FxPath = server.mappath(FxPath)
FxPath = replace(FxPath,"%2C",",")
else
FxPath = server.mappath(path)
end if
end function
%>
 
What happens if you hard code an HTML tag like: [tt]<a href=blah.ppt>test</a>[/tt]
 
Try using "View Source" to see the HTML code that is generated by your ASP. Perhaps the HTML is not exactly as it should be.
 
This is the link I get...

<a href="\erdb\open_file.asp?filename=38275.4750231481Triple%20Clamp%20Bushings.ppt&approved=1">

and it looks fine. Funny thing is same link works for other types of files. Only problem is powerpoint and it is killing me.
 
do you have powerpoint installed on the server??

dumb question may be but it doesnt hurt to make sure...

-DNG
 
Not sure about it but that should not matter, should it as I am downloading the file to my local machine and it downloads also but it has 0 bytes. If I try to open it on my local machine, it opens but does not contain any thing.
 
So if you had the following static HTML page then it would work?
[tt]
<html>
<head>
<title>Test Page</title>
</head>
<body>
<a href="\erdb\open_file.asp?filename=38275.4750231481Triple%20Clamp%20Bushings.ppt&approved=1">Click Here</a>
</body>
</html>
[/tt]
 
Shouldn't this line in function AddHeaders:

ContentType ="application/ms-powerpoint"

be

ContentType ="application/vnd.ms-powerpoint"

???
 
Thanks for all the inputs guys. But, nothing seems to be working yet. I tried ContentType ="application/vnd.ms-powerpoint" also but invain. Vexing issue is that the same thing works in our dev environment. Can anyone think of any solution please?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top