嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
从网页上传文件到服务器,可以按时间和类型分类
protected void UploadButton_Click(object sender, EventArgs e)
{
if (FileUploadControl.HasFiles)
{
string date1, date2;
date1 = DateTime.Now.ToShortTimeString();
if (TextBox1.Text == "")
{
date2 = TextBox1.Text; DateTime.Now.ToString("yyyy年MM月dd日");
}
else
{
date2 = TextBox1.Text;
}
StatusLabel.Text = "";
this.Label2.Text = this.TextBox3.Text;
try
{
string uploadFolder = Server.MapPath("~/ftp/文件/" this.Label2.Text "/" date2 "_" DropDownList_jcxm.Text "/");
if (!Directory.Exists(uploadFolder))
{
Directory.CreateDirectory(uploadFolder);
}
foreach (HttpPostedFile file in FileUploadControl.PostedFiles)
{
if (file.ContentLength > 0)
{
string fileName = Path.GetFileName(file.FileName);
string filePath = Path.Combine(uploadFolder, fileName);
file.SaveAs(filePath);
StatusLabel.Text = string.Format("文件 '{0}' 上传成功.<br />", fileName);
StatusLabel.ForeColor = System.Drawing.Color.Green; // 可选:设置消息颜色为绿色
Button2.Visible = true;
a1.InnerHtml = "";
}
}
}
catch (Exception ex)
{
StatusLabel.Text = "文件上传失败: " ex.Message;
StatusLabel.ForeColor = System.Drawing.Color.Red; // 可选:设置消息颜色为红色
a1.InnerHtml = "";
}
}
else
{
StatusLabel.Text = "请至少选择一个文件,不要选择空文件,支持多个文件同时上传!";
StatusLabel.ForeColor = System.Drawing.Color.Blue; // 可选:设置消息颜色为红色
a1.InnerHtml = "";
}
}