この方法を試してください:
<script runat="server">
protected void UploadButton_Click(object sender, EventArgs e)
{
string savePath = @"c:\temp\uploads\";
if (FileUpload1.HasFile)
{
// Get the size in bytes of the file to upload.
int fileSize = FileUpload1.PostedFile.ContentLength;
// Allow only files less than 2,100,000 bytes (approximately 2 MB) to be uploaded.
if (fileSize < 2100000)
{
// Append the name of the uploaded file to the path.
savePath += Server.HtmlEncode(FileUpload1.FileName);
FileUpload1.SaveAs(savePath);
UploadStatusLabel.Text = "Your file was uploaded successfully.";
}
else
{
UploadStatusLabel.Text = "Your file was not uploaded because " +
"it exceeds the 2 MB size limit.";
}
}
else
{
UploadStatusLabel.Text = "You did not specify a file to upload.";
}
}
</script>