在asp.net网站上上传文件夹 [英] uploading folder on a asp.net website

查看:71
本文介绍了在asp.net网站上上传文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在尝试在我的网站上导入一个按钮,用户可以在网站上传整个文件夹



我发现以下代码有效但只有一个文件

Hi guys,

I'm trying to import in my web site a button where the user will be able to upload the whole folder in the web site

I found the following code which works but only with a single file

if (IsPostBack)
        {
            Boolean fileOK = false;
            String path = Server.MapPath("~/UploadedImages/");
            if (FileUpload1.HasFile)
            {
                String fileExtension =
                    System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
                String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (fileExtension == allowedExtensions[i])
                    {
                        fileOK = true;
                    }
                }
            }

            if (fileOK)
            {
                try
                {
                    FileUpload1.PostedFile.SaveAs(path
                        + FileUpload1.FileName);
                    Label1.Text = "File uploaded!";
                }
                catch (Exception ex)
                {
                    Label1.Text = "File could not be uploaded.";
                }
            }
            else
            {
                Label1.Text = "Cannot accept files of this type.";
            }
        }







但我想上传整个文件夹里面的内容是最好的方法吗?



Thnx提前为你提供帮助和时间!!!




but I want to upload the whole folder with the contents inside which is the best way to do that?

Thnx in advance for your help and your time!!!

推荐答案

请参阅我对该问题的评论。我不仅解释了为什么你的代码不适用于整个文件夹,我解释了为什么它原则上不能像那样工作。您所能做的就是创建一些活动代码,这些代码将在客户端组合文件集并将它们放入HTTP请求中。你的想法本身非常好,我必须说,这样的事情很难实现,但这并不像你想象的那么简单。



问题是:到目前为止我看到的解决方案都基于使用ActiveXScripting.FileSystemObject。至少可以说这是一种肮脏的方法。首先,并非所有浏览器和系统都支持它。这(几乎)专门用于Microsoft系统和IE;即使其他浏览器可以通过插件实现,它仍然只适用于Microsoft OS上的客户端。更糟糕的是,这被认为是不安全的,因为ActiveX将为Web应用程序打开对客户端系统的广泛访问。许多精通计算机的用户在得知您使用ActiveX时绝不会使用您的网站。无论如何,您将能够轻松找到这样的解决方案: http://bit.ly/HEvPd8 [ ^ ]。



其他解决方案可能涉及Silverlight或Flash(应安装在客户端,但这样的解决方案更多平台;例如,有Mono版本的Silverligh for Mono版本称为Moonlight),或Java applet(更准确地说,是基于浏览器中使用的已安装JVM的applet,大多数客户应该拥有,但源语言可能与Java不同。)



请参阅:

http://www.michielpost.nl/Silverlight/MultiFileUploader/ [ ^ ],

http://www.vectorlight.net/sil verlight / demos / file_explorer.aspx [ ^ ],

http://jupload.sourceforge.net/applet-basic.html [ ^ ]。



等等......你无法用ASP.NET做任何事情。您可以尝试使用上面显示的搜索模式找到更多信息,在您可以考虑使用的技术上添加关键字。



-SA
Please see my comment to the question. Not only I explained why your code does not work for an entire folder, I explained why it cannot work like that in principle. All you can do is to create some active code which would assemble the set of files on the client side and put them in HTTP request. Your idea itself is very good, I must say, such thing would be great to achieve, but this is not as simple as you probably think.

The problems is: the solutions I saw so far are all based on the use of the ActiveX "Scripting.FileSystemObject". This is a dirty approach, to say the least. First of all, not all browsers and systems will support it. This is (almost) exclusively for Microsoft system and IE; even though some other browser can do it via a plug-in, it would still be only for clients on Microsoft OS. Worse, this is considered unsafe, because ActiveX would open wide access to the client's system for a Web application. Many computer-savvy users will never use your site when they learn that you use ActiveX. Anyway, you will be able to find such solutions easily: http://bit.ly/HEvPd8[^].

Other solutions may involve Silverlight or Flash (should be installed on client side, but such solutions are more multiplatform; for example, there is a Mono versions of Silverligh for Mono version called Moonlight), or Java applet (more exactly, an applet based on the installed JVM used in the browser, which most clients should have, but the source language could be different from Java).

Please see:
http://www.michielpost.nl/Silverlight/MultiFileUploader/[^],
http://www.vectorlight.net/silverlight/demos/file_explorer.aspx[^],
http://jupload.sourceforge.net/applet-basic.html[^].

And so on… Nothing you can do with ASP.NET along. You can try to find some more, using the search pattern shown above, adding keywords on the technology you could consider to use.

—SA


请参阅此内容,上传文件夹 [ ^ ]
See This, upload-folders[^]


这篇关于在asp.net网站上上传文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆