Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 1st, 2006, 07:36 AM
Pookie62 Pookie62 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 34 Pookie62 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 21 m 19 sec
Reputation Power: 4
Post Need help with opening files

Hi,

Found this script to browse the local network.
Is for Intranet use.
I can browse through the directories, but can't open the files displayed i.e *.doc, xls, pps files.
How should I do that ?
Since my knowledge of asp is nearly zero, is anyone willing to adjust this code ? Would really help me a lot..
Code:
<%@LANGUAGE="VBSCRIPT"%>
<%
   Option Explicit
   On Error Resume Next

  ' this section is optional - it just denies anonymous access
   If Request.ServerVariables("LOGON_USER")="" Then
     Response.Status = "401 Access Denied"
   End If


   ' declare variables
   Dim objFSO, objFolder
   Dim objCollection, objItem

   Dim strPhysicalPath, strTitle, strServerName
   Dim strPath, strTemp
   Dim strName, strFile, strExt, strAttr
   Dim intSizeB, intSizeK, intAttr, dtmDate

   ' declare constants
   Const vbReadOnly = 1
   Const vbHidden = 2
   Const vbSystem = 4
   Const vbVolume = 8
   Const vbDirectory = 16
   Const vbArchive = 32
   Const vbAlias = 64
   Const vbCompressed = 128

   ' don't cache the page
   Response.AddHeader "Pragma", "No-Cache"
   Response.CacheControl = "Private"

  ' get the current folder URL path
   strTemp = Mid(Request.ServerVariables("E:\Informatie"),2)
   strPath = ""

   Do While Instr(strTemp,"/")
      strPath = strPath & Left(strTemp,Instr(strTemp,"/"))
      strTemp = Mid(strTemp,Instr(strTemp,"/")+1)
   Loop

   strPath = "/" & strPath

   ' create the file system objects
   'strPhysicalPath = Server.MapPath(strPath)

   strName = objItem.Name
   
if request("dir") = "" then
   strPhysicalPath = "E:\Informatie"
ElseIf request("dir") = strName then
	strPhysicalPath = request("strName")
Else
   strPhysicalPath = request("dir")
End if


   Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
   Set objFolder = objFSO.GetFolder(strPhysicalPath)
   
   ' build the page title
   'strServerName = UCase(Request.ServerVariables("SERVER_NAME"))
   strTitle = "Contents of the " & strPhysicalPath & " folder"
	

%>
<html>
<head>
<title><%=strServerName%> - <%=strTitle%></title>
<style>
BODY  { BACKGROUND: #cccccc; COLOR: #000000;
        FONT-FAMILY: Arial; FONT-SIZE: 10pt; }
TABLE { BACKGROUND: #cccccc; COLOR: #ffffff; }
TH    { BACKGROUND: #000066; COLOR: #ffffff; }
TD    { BACKGROUND: #ffffff; COLOR: #000000; }
TT    { FONT-FAMILY: Courier; FONT-SIZE: 11pt; }
</style>
</head>
<body>

<h1 align="center"><%=strServerName%><br><%=strTitle%></h1>
<h4 align="center">Please choose a file/folder to view.</h4>

<div align="center"><center>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
   <th align="left">Name</th>
   <th align="left">KB</th>
   <th align="left">Type</th>
   <th align="left">Last Modified</th>
   <!--<th align="left">Bytes</th>-->
   <!--<th align="left">Attributes</th>-->
   <!--<th align="left">Ext</th>-->
   <!--<th align="left">Time</th>-->
</tr>

<%
   ''''''''''''''''''''''''''''''''''''''''
   ' output the folder list
   ''''''''''''''''''''''''''''''''''''''''

   Set objCollection = objFolder.SubFolders

   For Each objItem in objCollection
      strName = objItem.Name
      strAttr = MakeAttr(objItem.Attributes)
      dtmDate = CDate(objItem.DateLastModified)
%>
<tr>
   <td align="left"><b><a href="dirlist.asp?dir=<%=strPhysicalPath & "\" & strName%>"><%=strName%></a></b></td>
   <td align="right">N/A</td>
   <td align="left"><b><DIR></b></td>
   <td align="left"><%=FormatDateTime(dtmDate,vbShortDate)%></td>
   <!--<td align="right">N/A</td>-->
   <!--<td align="left"><tt><%=strAttr%></tt></td>-->
   <!--<td align="left"><b>Directory</b></td>-->
   <!--<td align="left"><%=FormatDateTime(dtmDate,vbLongTime)%></td>-->
</tr>
<% Next %>

<%
   ''''''''''''''''''''''''''''''''''''''''
   ' output the file list
   ''''''''''''''''''''''''''''''''''''''''
'	If Instr(strName,".xls") then								'Trying some stuff here, but no luck
'	response.ContentType = "application/vnd.ms-excel";   
'	response.AppendHeader("content-disposition", "attachment; filename=" strName);

'Response.ContentType = "application/msword"   ' Word
'Response.ContentType = "application/vnd.ms-excel"      'Excel
'Response.AddHeader "Content-Disposition", "attachment;filename=strFile.doc"

   
   Set objCollection = objFolder.Files

   For Each objItem in objCollection
      strName = objItem.Name
      strFile = Server.HTMLEncode(Lcase(strName))

      intSizeB = objItem.Size
      intSizeK = Int((intSizeB/1024) + .5)
      If intSizeK = 0 Then intSizeK = 1

      strAttr = MakeAttr(objItem.Attributes)
      strName = Ucase(objItem.ShortName)
      If Instr(strName,".") Then strExt = Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
      dtmDate = CDate(objItem.DateLastModified)
	  

%>
<tr>
   <td align="left"><a href="dirlist.asp?dir=<%=strPhysicalPath & "\" & strFile%>"><%=strFile%></a></td>
   <td align="right"><%=intSizeK%>K</td>
   <td align="left"><%=objItem.Type%></td>
   <td align="left"><%=FormatDateTime(dtmDate,vbShortDate)%></td>
   <!--<td align="right"><%=FormatNumber(intSizeB,0)%></td>-->
   <!--<td align="left"><tt><%=strAttr%></tt></td>-->
   <!--<td align="left"><%=strExt%></td>-->
   <!--<td align="left"><%=FormatDateTime(dtmDate,vbLongTime)%></td>-->
</tr>
<% Next %>

</table>
</center></div>

</body>
</html>
<%
   Set objFSO = Nothing
   Set objFolder = Nothing

   ' this adds the IIf() function to VBScript
   Function IIf(i,j,k)
      If i Then IIf = j Else IIf = k
   End Function

   ' this function creates a string from the file atttributes
   Function MakeAttr(intAttr)
      MakeAttr = MakeAttr & IIf(intAttr And vbArchive,"A","-")
      MakeAttr = MakeAttr & IIf(intAttr And vbSystem,"S","-")
      MakeAttr = MakeAttr & IIf(intAttr And vbHidden,"H","-")
      MakeAttr = MakeAttr & IIf(intAttr And vbReadOnly,"R","-")
   End Function
%>

Reply With Quote
  #2  
Old December 2nd, 2006, 03:07 PM
Shadow Wizard's Avatar
Shadow Wizard Shadow Wizard is offline
Moderator From Beyond
Click here for more information.
 
Join Date: Sep 2004
Location: Israel
Posts: 26,969 Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)Shadow Wizard User rank is General 8th Grade (Above 100000 Reputation Level)  Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1Folding Points: 342040 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Months 1 Week 5 Days 15 h 9 m 16 sec
Reputation Power: 1556
you already asked this question and got reply.
posting it again won't help you.
if you want, post reply in your existing thread and ask for what
you want.

--thread closed.

Reply With Quote
Closed Thread

Viewing: ASP Free ForumsOtherProgramming Help > Need help with opening files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway