When ASP is installed, the FileSystemObject and the TextStream object are automatically installed along with it. The ASP FileSystemObject allows you to work with drives, folders, and files on the server. The TextStream object allows you to create, read, and write files.
Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022


Working with Files in ASP

When ASP is installed, the FileSystemObject and the TextStream object are automatically installed along with it. The ASP FileSystemObject allows you to work with drives, folders, and files on the server. The TextStream object allows you to create, read, and write files.

In certain instances, you may not be sure that a specific file exists. In that case, you should use the FileSystemObject's FileExists method before attempting to access the file. Example code for this is shown below.

<%
Dim objFS

Set objFS = 
  Server.CreateObject("Scripting.FileSystemObject")
If objFS.FileExists("c:\asp\newfolder\newfile.txt") Then
  Response.Write "File exists"
Else
  Response.Write "File does not exist"
End If 

Set objFS = Nothing
%> 

When you enter a URL into the address bar in your Web browser, it consists of a domain name followed by a file path. The URL file path has no relation to the actual file path on a physical storage device because a website may be located or moved from one physical storage location to another without changing the URL of any file on that Web site. The path you enter into a Web browser is a "virtual path".

The ASP Server object represents the Web server itself and has a method named MapPath that accepts a virtual path and returns the actual physical path. Below is how a call to the MapPath method looks.

Server.MapPath(path)

For example, you could use the code shown below to determine the actual physical location of the web server.

<%
Dim strPath

strPath = Server.MapPath("/")
response.write(strPath)
%>

The resulting response from the above code might be "c:\inetpub\wwwroot". Note that you don't need to create the Server object because if the Web server is running, the server object already exists.

Generally, you would use the MapPath method to determine the actual physical path of a file from its virtual path, as shown below.

<%
Dim strPath

strPath = Server.MapPath("/foldername/filename.asp")
response.write(strPath)
%>

If the path argument doesn't start with a slash (/ or \), MapPath assumes that it is a path relative to the .asp file being processed. For example, if an .asp file located at the physical path c:\inetpub\wwwroot\myfolder\myfile1.asp calls the MapPath method with the code shown below.

<%
Dim strPath

strPath = Server.MapPath("../foldername/filename.asp")
response.write(strPath)
%>

The resulting response would be "c:\inetpub\wwwroot\foldername\filename.asp".

RSS Feed RSS Feed

Follow Stephen Bucaro Follow @Stephen Bucaro

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2017 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268