图片上传的例子

.cs

private int uploadpic()
{

if(myFile.PostedFile!=null)
{
try
{
string fileDir="C://Library//PagePic//"; //注此处可更改为你想要上传的目录
string fileName=System.IO.Path.GetFileName(myFile.PostedFile.FileName);
string filePath=System.IO.Path.Combine(fileDir,fileName);
LfikePath.Text=filePath;
myFile.PostedFile.SaveAs(filePath);
}
catch(Exception exc)
{
this.AlertBox(exc.Message);
return -1;


}
}

return 0;



}

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

if(uploadpic()==-1)
{
return;

}

}

.aspx

<<INPUT id="myFile" type="file" onchange="document.all.Ifytp.src=this.value" runat="server">>
<<asp:image id="Ifytp" runat="server" Width="72px">><</asp:image>>

你可能感兴趣的:(图片上传)