本文介绍了将文件上载到虚拟目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 -


我目前正在使用FileUpload控件允许人们将

文件上传到我的网站。这一切都很好,只要我在服务器上找到一个

物理路径。


但是,我需要允许人们上传到一个虚拟目录。

目录可能存在也可能不存在于与网站相同的服务器上。


我似乎无法弄清楚如何做到这一点。如果我将虚拟的

目录地址传递给FileUpload.SaveAs,它告诉我需要一个有根的

目录。如果我尝试从

Server.MapPath获取物理目录名称,则会抛出异常。


有没有办法获得物理路径到一个虚拟目录

所以我可以将它传递给FileUpload.SaveAs,或者另外一种方法来上传/删除虚拟目录中的文件?


提前谢谢。

Hi -

I''m currently using the FileUpload control to allow people to upload
files to my website. This all works fine, as long as I''m going to a
physical path on my server.

However, I need to allow people to upload to a virtual directory. The
directory may or may not exist on the same server as the Web site.

I can''t seem to figure out how to do this. If I pass the virtual
directory address to FileUpload.SaveAs, it tells me I need a rooted
directory. If I try to get the physical directory name from
Server.MapPath, it throws an exception.

Is there any way to either get the physical path to a virtual directory
so I can pass it to FileUpload.SaveAs, or an alternative method to
upload/delete files to and from a virtual directory?

Thanks in advance.

推荐答案








我没有从Server.MapPath获得异常,但我也没有得到

正确的物理路径。


我在IIS中设置了一个虚拟目录。让我们说我称之为

MyVirtualDirectory它指向d:\ MyFiles。


如果我试图找到MyVirtualDirectory的物理路径所以:


Server.MapPath(" MyVirtualDirectory")

它返回我当前的应用程序物理目录

MyVirtualDirectory最后附加,例如,

" C:\ MyyPNETProjects \ ThisProject \ MyVirtualDirector y"


也许这是一个设置问题?最终目标是允许用户将文件上传到虚拟目录指向的任何位置 - 这可能是同一服务器上的一个/ b $ b目录,或者完全不同的目录。



I don''t get an exception from Server.MapPath, but I also don''t get the
correct physical path.

I set up a virtual directory in IIS. Let''s say I call it
MyVirtualDirectory and it points to d:\MyFiles.

If I try to find the physical path of MyVirtualDirectory like so:

Server.MapPath("MyVirtualDirectory")

It returns my current application physical directory with
"MyVirtualDirectory" appended on the end, for example,
"C:\MyASPNETProjects\ThisProject\MyVirtualDirector y"

Maybe this is a setup issue? The ultimate goal is to allow the users to
upload files to wherever the virtual directory points - which may be a
directory on the same server, or a different one altogether.


这篇关于将文件上载到虚拟目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 19:54
查看更多