上传文件(code)
//上传到服务器的路径 (以后可以在这里改)
string savePath = Server.MapPath("");
//获取file控件取得的路径
string Path = File.Value;
string[] SplitPath = Path.Split('\\');
string lastPath = SplitPath[SplitPath.Length - 1];
string[] fileName = lastPath.Split('.');
string lastfile = fileName[fileName.Length - 1];
try
{
if (lastfile == "jpg")
{
savePath = savePath + "\\" + lastPath;
//上传文件到服务器 SaveAs
File.PostedFile.SaveAs(savePath);
labmessage.Text = "Uploaded";
}
else
{
labmessage.Text = "The file is not rigth";
}
}
catch(Exception ex)
{
labmessage.Text = ex.Message;
}

浙公网安备 33010602011771号