|
 |
asptoday_discuss thread: File System Object errors when file not on same server as script
Message #1 by "David ODonnell" <dodonnell@t...> on Mon, 1 Oct 2001 23:40:21
|
|
Hi, this script continually gives me errors if the file to include is
outside the virtual directory or on another server. Any ideas?
<%
'Pass the name of the file to the function.
Function getFileContents(strIncludeFile)
Dim objFSO
Dim objText
Dim strPage
'Instantiate the FileSystemObject Object.
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Open the file and pass it to a TextStream Object (objText). The
'"MapPath" function of the Server Object is used to get the
'physical path for the file.
Set objText = objFSO.OpenTextFile(Server.MapPath(strIncludeFile))
'Read and return the contents of the file as a string.
getFileContents = objText.ReadAll
objText.Close
Set objText = Nothing
Set objFSO = Nothing
End Function
%>
<%
'Declare variables to hold the content of the main page and
'the include file.
Dim strMain, strInclude, strGo
'Get the contents of the main page and pass them to the "strMain"
'variable.
strMain = getFileContents("../aspInc/home.html")
strGo = "YESSS!!!"
'Get the requested file and make a temporary copy inside this domain
If (strGo) = "" Then
strInclude = getFileContents
("http://213.229.185.31/commonDocs/default.htm")
Else
strInclude = getFileContents
("http://213.229.185.31/commonDocs/default.htm")
End If
'After the proper include file contents are loaded ("strInclude"),
'then insert it into the main page ("strMain") using the "Replace"
'function.
strMain = replace(strMain,"<!-- INCLUDE FILE HERE -->",strInclude)
'Use the "Response" Object to "Write" the completed page to the client.
Response.Write strMain
%>
Message #2 by "Tulip, Nick S" <nick.s.tulip@c...> on Tue, 2 Oct 2001 06:48:37 -0400
|
|
You can't reference an include file like an http address. I believe that the
include file has to reside only on the server where the script is running.
-----Original Message-----
From: David ODonnell [mailto:dodonnell@t...]
Sent: Monday, October 01, 2001 7:40 PM
To: ASPToday Discuss
Subject: [asptoday_discuss] File System Object errors when file not on
same server as script
Hi, this script continually gives me errors if the file to include is
outside the virtual directory or on another server. Any ideas?
<%
'Pass the name of the file to the function.
Function getFileContents(strIncludeFile)
Dim objFSO
Dim objText
Dim strPage
'Instantiate the FileSystemObject Object.
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
'Open the file and pass it to a TextStream Object (objText). The
'"MapPath" function of the Server Object is used to get the
'physical path for the file.
Set objText = objFSO.OpenTextFile(Server.MapPath(strIncludeFile))
'Read and return the contents of the file as a string.
getFileContents = objText.ReadAll
objText.Close
Set objText = Nothing
Set objFSO = Nothing
End Function
%>
<%
'Declare variables to hold the content of the main page and
'the include file.
Dim strMain, strInclude, strGo
'Get the contents of the main page and pass them to the "strMain"
'variable.
strMain = getFileContents("../aspInc/home.html")
strGo = "YESSS!!!"
'Get the requested file and make a temporary copy inside this domain
If (strGo) = "" Then
strInclude = getFileContents
("http://213.229.185.31/commonDocs/default.htm")
Else
strInclude = getFileContents
("http://213.229.185.31/commonDocs/default.htm")
End If
'After the proper include file contents are loaded ("strInclude"),
'then insert it into the main page ("strMain") using the "Replace"
'function.
strMain = replace(strMain,"<!-- INCLUDE FILE HERE -->",strInclude)
'Use the "Response" Object to "Write" the completed page to the client.
Response.Write strMain
%>
Message #3 by "joseph saenz" <niceguy5150@h...> on Tue, 30 Oct 2001 00:23:13
|
|
basically, the problem that i had when i was programming with the
filesystemobject was that for different functions you need to reference
servers differently. there is the "\\****\*.*" way and then there is
the "D:/***/***.*" One references the file virtually and the other does
it specifically. i had major problems figuring this out because all the
webpages about the object online are conflicting. also, you should check
that the directory that you are accessing has scripting priviledges for
anonymous web users. it depends on what functions you are using but it
may also be responsible. those are the two problems that i had with the
object.
hope that helps some.
joseph saenz
cheif programmer
card2net
http://www.card2net.com/
> Hi, this script continually gives me errors if the file to include is
> outside the virtual directory or on another server. Any ideas?
>
>
>
> <%
>
> 'Pass the name of the file to the function.
> Function getFileContents(strIncludeFile)
> Dim objFSO
> Dim objText
> Dim strPage
>
>
>
> 'Instantiate the FileSystemObject Object.
> Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
>
>
> 'Open the file and pass it to a TextStream Object (objText). The
> '"MapPath" function of the Server Object is used to get the
> 'physical path for the file.
> Set objText = objFSO.OpenTextFile(Server.MapPath(strIncludeFile))
>
>
> 'Read and return the contents of the file as a string.
> getFileContents = objText.ReadAll
>
> objText.Close
> Set objText = Nothing
> Set objFSO = Nothing
> End Function
> %>
>
> <%
>
> 'Declare variables to hold the content of the main page and
> 'the include file.
> Dim strMain, strInclude, strGo
>
> 'Get the contents of the main page and pass them to the "strMain"
> 'variable.
> strMain = getFileContents("../aspInc/home.html")
> strGo = "YESSS!!!"
>
> 'Get the requested file and make a temporary copy inside this domain
>
>
>
> If (strGo) = "" Then
> strInclude = getFileContents
> ("http://213.229.185.31/commonDocs/default.htm")
> Else
> strInclude = getFileContents
> ("http://213.229.185.31/commonDocs/default.htm")
> End If
>
>
>
> 'After the proper include file contents are loaded ("strInclude"),
> 'then insert it into the main page ("strMain") using the "Replace"
> 'function.
> strMain = replace(strMain,"<!-- INCLUDE FILE HERE -->",strInclude)
>
> 'Use the "Response" Object to "Write" the completed page to the client.
> Response.Write strMain
> %>
|
|
 |