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!

Welcome to 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 Advertise on Bucaro TecHelp Advertise Here RSS News Feeds News Feeds


Hello World! Computer Programming for Kids and Other Beginners

Hello World! Computer Programming for Kids and Other Beginners

This book provides a gentle but thorough introduction to computer programming. It's written in language a kid can follow, but anyone who wants to learn how to program a computer can use it. Even adults.

Teaches using the powerful object-oriented but easy-to-use open source Python programming language.

Click Here

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".

Programming Sections

RSS Feed RSS Feed

Active Server Pages


[Site User Agreement] [Advertise on This site] [Search This Site] [Contact Form]
Copyright©2001-2011 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268