我想在提交时创建一个文件夹,然后将文件保存在新创建的文件夹中?

编程入门 行业动态 更新时间:2024-10-21 20:37:26
本文介绍了我想在提交时创建一个文件夹,然后将文件保存在新创建的文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的代码隐藏文件,其中按钮点击事件在那里,我保存在文件夹中发送的所有附件,但现在我想创建一个包含电子邮件主题的文件夹,并将该附件保存在该文件夹中请帮助!! !

This is my code behind file where button click event is there and i am saving all the attachments that are sent in a folder but now i want to create a folder with email subject and save that attachment in that folder pls help!!!

protected void Button1_Click(object sender, EventArgs e) { string temp = ""; Email em = new Email(); if (FileUpload1.HasFile) { System.IO.Directory.CreateDirectory(MapPath("~/Mail_Attachments/" + txtSubject.Text )); FileUpload1.SaveAs(MapPath("~/Mail_Attachments/" + txtSubject.Text + FileUpload1.FileName)); temp = "~/Mail_Attachments/" + txtSubject.Text + FileUpload1.FileName; } foreach (GridViewRow row in GridView1.Rows) { Label Name = row.FindControl("Label1") as Label; Label Email_Id = row.FindControl("Label2") as Label; Label Date_Time = row.FindControl("Label4") as Label; CheckBox cb = (CheckBox)row.FindControl("CheckBox1"); if (cb.Checked == true) { Dashboard dsb = new Dashboard(); dsb.Name = Name.Text; dsb.Email_Id = Email_Id.Text; dsb.Date_Time = System.DateTime.Now.ToString(); dsb.Subject = txtSubject.Text; dsb.Body = txtBody.Text; dsb.Attachments = temp; md.Dashboards.InsertOnSubmit(dsb); md.SubmitChanges(); //em.InsertData(Name.Text, Email_Id.Text, System.DateTime.Now.ToString(),txtSubject.Text,txtBody.Text,temp); } } }

推荐答案

试试这个。希望这是你想要的。 Try this. Hope this what you want. if (FileUpload1.HasFile) { string directoryPath = "~/Mail_Attachments/" + txtSubject.Text; string filePath = directoryPath + "/" + FileUpload1.FileName; if (!Directory.Exists(MapPath(directoryPath))) System.IO.Directory.CreateDirectory(MapPath(directoryPath )); FileUpload1.SaveAs(MapPathfilePath )); temp = filePath ; }

你可以试试这个代码.. Can u try this code.. string directoryPath = Server.MapPath(string.Format("~/Mail_Attachments/"+ txtSubject.Text)); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); FileUpload1.SaveAs(MapPath("~/Mail_Attachments/" + txtSubject.Text + FileUpload1.FileName)); }

更多推荐

我想在提交时创建一个文件夹,然后将文件保存在新创建的文件夹中?

本文发布于:2023-11-12 12:01:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581449.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我想   文件   创建一个   文件夹   夹中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!