string num = Label1.Text;
string file_path = FileUpload1.PostedFile.FileName.ToLower();
string filename = ""; // 上传文件的文件名(原名)
int size = FileUpload1.PostedFile.ContentLength;//上传文件的大小
string root = Server.MapPath("~/upload/");
if (file_path.Equals(""))
{
Response.Write("<script>alert('请选择文件!')</script>");
return;
}
if (size == 0)
{
Response.Write("<script>alert('找不到文件!')</script>");
return;
}
// 对文件名进行处理,使该文件名是唯一的,这里的做法是加入文件上传的时间;
int position = file_path.LastIndexOf("\\");
filename = file_path.Substring(position + 1);
string uploadfile = num + filename;
// 判断upload目录是否存在,如果不存在就创建该目录;
if (!Directory.Exists(root))
{
Directory.CreateDirectory(root);
}
// 指明上传的路径
string destination = root + uploadfile;
// 在服务器保存文件;
FileUpload1.PostedFile.SaveAs(destination);
//存入数据库
SqlConnection meteor = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["meteor"]);
meteor.Open();
SqlCommand cmd = new SqlCommand("update
studentinformation set uploadfile='" + uploadfile + "', filename='" + filename + "',destination ='" + destination + "'where studentnum='" + Label1.Text + "'", meteor);
cmd.ExecuteNonQuery();
meteor.Close();
PathLab.Text = "您上传的简历大小为:" + size.ToString() + "bytes";
Response.Write("<script>alert('上传成功!')</script>");
这个是我上传简历时用的程序.