如何在将文档上传到该文件夹​​时创建命名文件夹

如何在将文档上传到该文件夹​​时创建命名文件夹

本文介绍了嗨,如何在将文档上传到该文件夹​​时创建命名文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了上传文件,我想创建文件夹并希望在上传时为该文件夹命名.如何做到这一点可以帮助我吗?

或例如.
在我的aspx项目中,我创建了许多带有名称的文件夹,并且在上载时我想保存在该特定文件夹中..任何人都可以建议我..?

还是我可以例如这样尝试..

[浏览文件]
[文本框]
[上传按钮]

在这里,我将描述..当我浏览文件并在输入的文本框中输入为路径(表示我想保存在我在项目中创建的文件夹中,因此我将在该文本框中键入该文件夹的名称..之后,我将单击uploadbutton,因此当我将我的tat文件上传到该输入的文件夹中时...我们可以这样做吗?我将向您展示我的代码,并在其中进行更改以帮助我实现这一目标...

hi i created uploading and i want to create folder and want to name for that folder while uploading..how to do that can any one help me??

or for example..
in my aspx project i created many folders with name and while uploading i want to save in that particular folder..can any one suggest me..?

or can i try like this for example..

[browse file]
[textbox]
[uploadbutton]

here i wil describe..when i browse file and enter in textbox filed as Path(mean i want to save in that folder which i created in my project so i wil type that folder name to that text box..after that i wil click uploadbutton so when i upload i want tat file into that entered folder...can any one can we do like that?? i will show u my code and where i have to make changes for that help me for this...

protected void btnUpload_Click(object sender, EventArgs e)
   {


       if (FileUpload1.HasFile == false)
       {

           UplodDetails.Text = "Please first select a file to upload...";
       }
       else
       {

           UplodDetails.Text = string.Format(@"Uploaded file: {0}<br />File size (in bytes):{1:N0}<br />Content-type: {2}",
                     FileUpload1.FileName,
                     FileUpload1.FileBytes.Length,
                     FileUpload1.PostedFile.ContentType);

           string filePath =
           Server.MapPath("~Uploader" + FileUpload1.FileName);

           FileUpload1.SaveAs(filePath);


       }

推荐答案

if (!Directory.Exists(Server.MapPath(filePath)))
{                                      Directory.CreateDirectory(Server.MapPath(filePath));
}


这篇关于嗨,如何在将文档上传到该文件夹​​时创建命名文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 09:16