将文件上载到虚拟目录 [英] Uploading files to a virtual directory

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

问题描述

嗨 -


我目前正在使用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应该可以使用。你有什么例外?可能是

许可问题吗?


-

Patrice


B Letts < BL **** @ klinitek.com> aécritdansle message de

news:uE ************** @ TK2MSFTNGP12.phx.gbl ...
Server.MapPath should work. What exception do you have ? Could it be a
permission issue ?

--
Patrice

"B Letts" <bl****@klinitek.com> a écrit dans le message de
news:uE**************@TK2MSFTNGP12.phx.gbl...
嗨 -

我目前正在使用FileUpload控件允许人们将
文件上传到我的网站。这一切都很好,只要我在我的服务器上进入物理路径。

但是,我需要允许人们上传到虚拟目录。
目录可能存在也可能不存在于与网站相同的服务器上。

我似乎无法弄清楚如何做到这一点。如果我将虚拟的
目录地址传递给FileUpload.SaveAs,它告诉我需要一个root的
目录。如果我尝试从服务器.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.



必须在文件系统级别从服务器访问它才能上传它。您可以使用MapPath()将http路径转换为文件

系统路径,但服务器必须可以访问该文件系统路径

....

-

Curt Christianson

网站: http://www.darkfalz.com

博客: http://blog.darkfalz.com


" B Letts"写道:
It will have to be accessible at the file system level from the server to
upload it. You can use the MapPath() to convert the http path to a file
system path but the server has to have that file system path accessible to
it....
--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"B Letts" wrote:
嗨 -

我正在使用FileUpload控件允许人们将
文件上传到我的网站。这一切都很好,只要我在我的服务器上进入物理路径。

但是,我需要允许人们上传到虚拟目录。
目录可能存在也可能不存在于与网站相同的服务器上。

我似乎无法弄清楚如何做到这一点。如果我将虚拟的
目录地址传递给FileUpload.SaveAs,它告诉我需要一个root的
目录。如果我尝试从服务器.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.



Patrice写道:
Patrice wrote:
Server.MapPath应该可以工作。你有什么例外?可能是
权限问题吗?
Server.MapPath should work. What exception do you have ? Could it be a
permission issue ?




我没有从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.


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

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