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

今天大家说什么也要救救我啊!!!
最近越到一个太麻烦太麻烦的事了(也可能是对于我来说.)
有一个项目,那个要求是,

有两个文件夹,一个是pic   ,一个是code

在code里面制作一个index.aspx的文件,

在文件里面做一个浏览,然后一个按钮,

让浏览后选中一个图片(应该就是一个 <input   type= "file "   /> ),单机按钮后把这个图片的名字改成111.***(***代表jpg或gif)

然后存入到pic这个文件夹内....请大家帮帮我吧,就应该是一个上传文件,然后改一下名,存到pic文件夹里.

这个我估计对于高手来说也就10分钟的事,可对于我这个不懂上传的人来说太费劲,
麻烦有时间的高手帮忙编一个!!!谢谢了,,(不要网址连接)

------解决方案--------------------
//aspx
<body>
<form id= "Form1 " method= "post " runat= "server ">
<INPUT id= "File1 " type= "file " name= "File1 " runat= "server ">
<asp:Button id= "Button1 " runat= "server " Text= "Button "> </asp:Button> &nbsp;
</form>
</FORM>
</body>

//aspx.cs
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.HtmlControls.HtmlInputFile File1;


private void Page_Load(object sender, System.EventArgs e)
{

}


#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}

private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Button1_Click(object sender, System.EventArgs e)
{
string myFileName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf( '. '));
string strPath = Server.MapPath( "../pic/111 " + myFileName);
File1.PostedFile.SaveAs(strPath);
}

记得给你的pic目录添加Network Service 用户的写入权限