蓝
蓝叶菱
Unregistered / Unconfirmed
GUEST, unregistred user!
upload.aspx
---------
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="upload.aspx.cs"
Inherits="upload"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
>
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1"
runat="server">
<div style="text-align: center">
<strong>UPLOAD SAMPLE<br />
<br />
<input id="File1"
style="width: 473px"
type="file"
/><br />
<br />
<input id="File2"
style="width: 471px"
type="file"
/><br />
<br />
<input id="File3"
style="width: 469px"
type="file"
/><br />
<br />
<input id="File4"
style="width: 469px"
type="file"
/><br />
<asp:LinkButton ID="LinkButton1"
runat="server">LinkButton</asp:LinkButton>
<a href="JavaScript:document.forms[0].reset()"
id="LinkButton2"
style="FONT-WEIGHT:bold;FONT-SIZE:xx-small;FONT-FAMILY:verdana">
Reset Form</A> <STRONG>::</STRONG>
<P>
<br />
<asp:Label ID="Label1"
runat="server"
Text="Label"
Width="440px"></asp:Label>
<asp:Label ID="Label2"
runat="server"
Text="Label"
Width="188px"></asp:Label>
</strong></div>
</form>
</body>
</html>
--------------
upload.asp.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
this.SaveImages();
}
private System.Boolean SaveImages()
{
//loop through the files uploaded
System.Web.HttpFileCollection _files = System.Web.HttpContext.Current.Request.Files;
//Message to the user
System.Text.StringBuilder _message = new System.Text.StringBuilder("Files Uploaded:<br>"
Label2.Text =System.Convert.ToString( System.Web.HttpContext.Current.Request.Files.Count);
//为什么这里,没有得到input file的数量啊.
try
{
for (System.Int32 _iFile = 0;
_iFile < _files.Count;
_iFile++)
{
// Check to make sure the uploaded file is a jpg or gif
System.Web.HttpPostedFile _postedFile = _files[_iFile];
System.String _fileName, _fileExtension;
_fileName = System.IO.Path.GetFileName(
_postedFile.FileName);
_fileExtension = System.IO.Path.GetExtension(
_fileName);
if (_fileExtension == ".gif"
{
//Save File to the proper directory
_postedFile.SaveAs(
System.Web.HttpContext.Current.Request.MapPath(
"gifs/" + _fileName);
_message.Append(_fileName + "<BR>"
}
else
if (_fileExtension == ".jpg"
{
//Save File to the proper directory
_postedFile.SaveAs(
System.Web.HttpContext.Current.Request.MapPath(
"jpgs/" + _fileName);
_message.Append(_fileName + "<BR>"
}
else
{
_message.Append(_fileName + "
<font color=/"red/">failed!! Only .gif and .jpg images allowed!</font> <BR>"
}
}
Label1.Text = _message.ToString();
return true;
}
catch (System.Exception Ex)
{
Label1.Text = Ex.Message;
return false;
}
}
}
-------------
为什么request.Fiels取不到任何值。。。。。。。。。。。。。。。。
---------
<%@ Page Language="C#"
AutoEventWireup="true"
CodeFile="upload.aspx.cs"
Inherits="upload"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
>
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1"
runat="server">
<div style="text-align: center">
<strong>UPLOAD SAMPLE<br />
<br />
<input id="File1"
style="width: 473px"
type="file"
/><br />
<br />
<input id="File2"
style="width: 471px"
type="file"
/><br />
<br />
<input id="File3"
style="width: 469px"
type="file"
/><br />
<br />
<input id="File4"
style="width: 469px"
type="file"
/><br />
<asp:LinkButton ID="LinkButton1"
runat="server">LinkButton</asp:LinkButton>
<a href="JavaScript:document.forms[0].reset()"
id="LinkButton2"
style="FONT-WEIGHT:bold;FONT-SIZE:xx-small;FONT-FAMILY:verdana">
Reset Form</A> <STRONG>::</STRONG>
<P>
<br />
<asp:Label ID="Label1"
runat="server"
Text="Label"
Width="440px"></asp:Label>
<asp:Label ID="Label2"
runat="server"
Text="Label"
Width="188px"></asp:Label>
</strong></div>
</form>
</body>
</html>
--------------
upload.asp.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
this.SaveImages();
}
private System.Boolean SaveImages()
{
//loop through the files uploaded
System.Web.HttpFileCollection _files = System.Web.HttpContext.Current.Request.Files;
//Message to the user
System.Text.StringBuilder _message = new System.Text.StringBuilder("Files Uploaded:<br>"
Label2.Text =System.Convert.ToString( System.Web.HttpContext.Current.Request.Files.Count);
//为什么这里,没有得到input file的数量啊.
try
{
for (System.Int32 _iFile = 0;
_iFile < _files.Count;
_iFile++)
{
// Check to make sure the uploaded file is a jpg or gif
System.Web.HttpPostedFile _postedFile = _files[_iFile];
System.String _fileName, _fileExtension;
_fileName = System.IO.Path.GetFileName(
_postedFile.FileName);
_fileExtension = System.IO.Path.GetExtension(
_fileName);
if (_fileExtension == ".gif"
{
//Save File to the proper directory
_postedFile.SaveAs(
System.Web.HttpContext.Current.Request.MapPath(
"gifs/" + _fileName);
_message.Append(_fileName + "<BR>"
}
else
if (_fileExtension == ".jpg"
{
//Save File to the proper directory
_postedFile.SaveAs(
System.Web.HttpContext.Current.Request.MapPath(
"jpgs/" + _fileName);
_message.Append(_fileName + "<BR>"
}
else
{
_message.Append(_fileName + "
<font color=/"red/">failed!! Only .gif and .jpg images allowed!</font> <BR>"
}
}
Label1.Text = _message.ToString();
return true;
}
catch (System.Exception Ex)
{
Label1.Text = Ex.Message;
return false;
}
}
}
-------------
为什么request.Fiels取不到任何值。。。。。。。。。。。。。。。。