日期:2014-05-19  浏览次数:20848 次

c#上传问题?我怎么提交不到服务器(代码在文章中)
up2.aspx

<%@   Page   language= "c# "   Codebehind= "up2.aspx.cs "   AutoEventWireup= "false "   Inherits= "uploadtest.up2 "   %>
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN "   >
<HTML>
<HEAD>
<title> up2 </title>
<meta   name= "GENERATOR "   Content= "Microsoft   Visual   Studio   .NET   7.1 ">
<meta   name= "CODE_LANGUAGE "   Content= "C# ">
<meta   name= "vs_defaultClientScript "   content= "JavaScript ">
<meta   name= "vs_targetSchema "   content= "http://schemas.microsoft.com/intellisense/ie5 ">
</HEAD>
<body   MS_POSITIONING= "GridLayout ">
<form   id= "Form1 "   method= "post "   runat= "server ">
<table>
<tr   bgcolor= "#ffffff ">
<td   height= "24 ">
<input   type= "file "   id= "Up_file "   class= "edline "   runat= "server "   style= "WIDTH:   456px;   HEIGHT:   20px "
size= "60 "   name= "Up_file ">
</td>
</tr>
<TR   bgcolor= "#ffffff ">
<TD   height= "24 "   align= "center ">
<asp:Button   ID= "submit "   Runat= "server "   Text= "文件上传 "   CssClass= "Cmdbut "   Height= "20px "> </asp:Button>
</TD>
</TR>
</table>
</form>
</body>
</HTML>

up2.aspx.cs

using   System;
using   System.Collections;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Web;
using   System.Web.SessionState;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.HtmlControls;
using   System.IO;
namespace   uploadtest
{
///   <summary>
///   up2   的摘要说明。
///   </summary>
public   class   up2   :   System.Web.UI.Page
{
protected   System.Web.UI.WebControls.Button   submit;
protected   System.Web.UI.HtmlControls.HtmlInputFile   Up_file;

private   void   Page_Load(object   sender,   System.EventArgs   e)
{
//   在此处放置用户代码以初始化页面
}
private   void   submit_Click(object   sender,   System.EventArgs   e)
{
HttpPostedFile   postedFile   =   this.Up_file.PostedFile;   //得到要上传文件
string   fileName,   fileExtension;
fileName   =   System.IO.Path.GetFileName(postedFile.FileName);   //文件名称

if   (fileName   !=   " ")
{
fileExtension   =   System.IO.Path.GetExtension(fileName);   //上传文件的扩展名
string   new_filename   =   fileExtension;   //给文件重新命名
//postedFile.FileName:   客户端文件地址
//postedFile.ContentType.ToString():   上传的文件类型
//保存文件到文件夹,地址是当前页面的同一级目录下的files文件夹中

postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath( "aaa/ ")   +   new_filename);