如何从 C# 代码在服务器上创建文件夹?

发布于 2024-12-04 01:33:35 字数 172 浏览 0 评论 0原文

有没有办法向用户显示弹出窗口以给出创建文件夹的名称

如果他不想创建文件夹那么应该向他显示他想要保存文件的文件夹列表

这是我创建的正确方法吗一个带有 javascript 的弹出窗口,其中包含我的服务器上的文件夹列表,并放置一个文本框和按钮来保存新的,在代码中我们将在通过文本框传递的代码中创建目录?

Is there any way to show user popup to give the name to create folder

And with that if he does not want to create folder then he should be shown the list of folders to which he want to save the file

Is it proper way that I create a popup with javascript with the list of folders on my server and put a textbox and button to save the new and in code we will create directory in code passed with textbox?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

无人问我粥可暖 2024-12-11 01:33:35
string pathToCreate = "~/UserFolders/" + TextBox1.Text;
if(Directory.Exists(Server.MapPath(pathToCreate))
{
   //In here, start looping and modify the path to create to add a number
   //until you get the value needed
}

//Now you know it is ok, create it
Directory.CreateDirectory(Server.MapPath(pathToCreate));
string pathToCreate = "~/UserFolders/" + TextBox1.Text;
if(Directory.Exists(Server.MapPath(pathToCreate))
{
   //In here, start looping and modify the path to create to add a number
   //until you get the value needed
}

//Now you know it is ok, create it
Directory.CreateDirectory(Server.MapPath(pathToCreate));
梦晓ヶ微光ヅ倾城 2024-12-11 01:33:35
                        string targetPath = Server.MapPath("FolderName"); //with complete path
                        if (!System.IO.Directory.Exists(targetPath))
                        {
                            System.IO.Directory.CreateDirectory(targetPath);                               
                            fileToUpload.PostedFile.SaveAs(targetPath + ImageFileName);
                        }
                        else
                        {
                            fileToUpload.PostedFile.SaveAs(targetPath + ImageFileName);
                        }
                        string targetPath = Server.MapPath("FolderName"); //with complete path
                        if (!System.IO.Directory.Exists(targetPath))
                        {
                            System.IO.Directory.CreateDirectory(targetPath);                               
                            fileToUpload.PostedFile.SaveAs(targetPath + ImageFileName);
                        }
                        else
                        {
                            fileToUpload.PostedFile.SaveAs(targetPath + ImageFileName);
                        }
挽你眉间 2024-12-11 01:33:35

正如我在评论中提到的,SaveFileDialog 这样的功能只能在 Windows 窗体应用程序中实现,您不能在 asp.net 中执行此操作

。或者,网上有一个名为 CKEditor 3.x Developer’s 的第三方编辑器指南

您可以使用文件浏览器(上传器)来达到您想要的目的来实现。

As I mentioned by commenting that Functionality like SaveFileDialog is only possible in Windows Forms application, you cannot do this in asp.net

The alternatives in asp.net are difficult however as an alternate there is a third party editor available on the web called CKEditor 3.x Developer's Guide.

You can use File Browser (Uploader) for the purpose you want to achieve.

梦里人 2024-12-11 01:33:35

创建文件夹:

 System.IO.Directory.CreateDirectory(newPath);//newpath is your folder creating path

to create folder :

 System.IO.Directory.CreateDirectory(newPath);//newpath is your folder creating path
眼泪也成诗 2024-12-11 01:33:35

如果您正在开发 Web 应用程序(我可以看到您已将问题标记为 asp.net),则无需担心弹出窗口。您只需通过响应发送文件,浏览器就会显示下载窗口。

If you are developing web applications (I can see you have tagged your question as asp.net), you do not need to worry about the pop up window. You just send the file through the Response and the download window will be shown by the browser.

万劫不复 2024-12-11 01:33:35

使用如何创建文件夹或文件中给出的示例,您可以创建一个文件夹,但在 asp.net 中,您不能使用打开文件对话框或保存文件对话框功能,这仅适用于 C# Windows 窗体应用程序。

Using the Example given in How to Create a Folder or File You can create a folder, but in asp.net you can not Use open file dialog or save file dialog functionalities, this will work only in C# Windows forms application.

三岁铭 2024-12-11 01:33:35

Web 应用程序和 HTTP 协议不支持直接操作服务器端文件系统。事实上,这是一个危险的想法。

听起来您在 Web 服务器上的某个位置有一个基本文件夹,您希望用户能够在其中上传文件,并且用户可以控制子文件夹和上传文件的位置。我建议通过在树视图或链接列表中显示文件系统(其中链接允许您在文件夹树中向上/向下导航)来实现这一点。将其与文件输入结合起来,您就得到了一个解决方案。但是,要非常小心地控制和清理上传文件的指定文件名。有许多组合(例如使用“..”)可以允许用户侵入服务器上不需要的文件位置。

Web applications and the HTTP protocol do not support direct manipulation of the server-side file system. In fact, that would be a dangerous idea.

It sounds like you have a base folder somewhere on the web server where you want users to be able to upload files, with some user control over subfolders and location of the uploaded file. I would suggest dong this by presenting the file system in a tree view or a list of links (where the links let you navigate up/down the folder tree). Combine this with a file input and you've got yourself a solution. HOWEVER, be very careful to control and cleanse the specified file name for the uploaded file. There are many combinations (such as utilizing "..") that can allow the user to hack into unwanted file locations on your server.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文