The Request.Upload Object
The Request.Upload property enables
you to handle file uploads using multipart/form-data forms. The Request.Upload.Files property is an object that implements
the IRequestDictionary interface like Request.Cookies, Request.Forms,
Request.ServerVariables do. Every element of Request.Upload.Files
contains the following methods and properties: FileName:string; FieldName:string;
ContentType:string; Size:integer; SaveAs(FileName:string; Overwrite:
boolean = False):boolean; The FileName property contains the name
of the uploaded file. The FiledName property identifies the form field
name of the uploaded file. The ContentType property contains the content
type of the uploaded file. The Size property contains the size of
the uploaded file. The SaveAs() method allows
you to save the file with the name provided in the first field (FileName).
If the Overwrite field is set to True, the file will be saved even
if it already exists as a file with the same name. This method returns
a boolean value with the result of the saving procedure.
Request.Upload contains the following
property:
-
Files
The Request.Upload.Files property is
an object that implements the IRequestDictionary interface like Request.Cookies, Request.Forms, and Request.ServerVariables. Every element of Request.Upload.Files contain
the following methods and properties:
-
FileName:string;– Contains the name of the uploaded file. -
FieldName:string;– Identifies the form field name of the uploaded file. -
ContentType:string;– Contains the content type of the uploaded file. -
Size:integer;– Contains the size of the uploaded file. -
SaveAs(FileName:string; Overwrite: boolean = False):boolean;– Enables you to save the file with the name provided in the first field (FileName). If theOverwritefield is set toTrue, the file will be saved even if it already exists. This method returns a boolean value with the result of the saving procedure.
<form method="post" enctype="multipart/form-data">
File: <input name="uploadedfile" type="file" /><br/>
<input type="submit" />
if (Request.Upload.Files.Count > 0) then
Dim FileName
FileName = Request.Upload.Files("uploadedfile").FileName
Response.Write("Uploaded file: " + FileName + "<br/>")
if (Request.Upload.Files("uploadedfile").SaveAs(Server.MapPath(FileName), True)) then
Response.Write(FileName + " has been succesfully saved!")
else
Response.Write(FileName + " hasn't been succesfully saved!")
end if
end if
%>

