.net 上传word到指定的文件夹
protected void 上传_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileInfo fi = new FileInfo(FileUpload1.FileName);
if (fi.Extension == ".doc")
{
string wordPath = directPath;//文件夹路径
string wordRealName = FileUpload1.FileName.Replace(".doc", "");//显示名称
DateTime dateTime = DateTime.Now;
string uploadTime = string.Format("{0:yyyy年MM月dd日}", dateTime);//上传时间
string wordVirtualName = string.Format("{0:yyyyMMddHHmmssffff}", dateTime);//实际名称
newFile = Server.MapPath("~" + wordPath) + "/" + wordVirtualName + ".doc";//全路径
if (!Directory.Exists(Server.MapPath("~" + wordPath)))
{
Directory.CreateDirectory(Server.MapPath("~" + wordPath));
}
FileUpload1.PostedFile.SaveAs(newFile);
string filePath = wordPath + "/" + wordVirtualName + ".doc";//相对路径
//将文档信息填入数据库
string sql = "";
executor.executNonQuery(sql);
Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), new Guid().ToString(), "<script>alert('文件保存成功')</script>");
logInfoclass.InsertLogInfo("上传word文档\"" + wordRealName + "\"", LogType.Handle);
}
else
{
Page.ClientScript.RegisterClientScriptBlock(this.Page.GetType(), new Guid().ToString(), "<script>alert('请选择后缀为doc的文件')</script>");
}
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), Guid.NewGuid().ToString(), "<script>alert('请选择文件!')</script>");
}
}
浙公网安备 33010602011771号