本文介绍了我想在提交时创建一个文件夹,然后将文件保存在新创建的文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码隐藏文件,其中按钮点击事件在那里,我保存在文件夹中发送的所有附件,但现在我想创建一个包含电子邮件主题的文件夹,并将该附件保存在该文件夹中请帮助!! !
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)); }
更多推荐
我想在提交时创建一个文件夹,然后将文件保存在新创建的文件夹中?
发布评论