473,378 Members | 1,119 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Uploading files to a virtual directory

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.
Nov 19 '05 #1
16 11688
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...
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.

Nov 19 '05 #2
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:
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.

Nov 19 '05 #3
Patrice wrote:
Server.MapPath should work. What exception do you have ? Could it be a
permission issue ?


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.

Nov 19 '05 #4
What if you try "/MyVirtualDirectory" or "~/MyVirtualDirectory" instead ?

IMO Server.MapPath resolves the root and then add the relative path
resolving the relative path to a local directory.
Using an absolute path should hopefully solve this issue.

--
Patrice

"B Letts" <bl****@klinitek.com> a écrit dans le message de
news:ej**************@TK2MSFTNGP12.phx.gbl...
Patrice wrote:
Server.MapPath should work. What exception do you have ? Could it be a
permission issue ?


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.

Nov 19 '05 #5
Try
Server.MapPath("/MyVirtualDirectory") and see what you get.

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"B Letts" wrote:
Patrice wrote:
Server.MapPath should work. What exception do you have ? Could it be a
permission issue ?


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.

Nov 19 '05 #6
Curt_C [MVP] wrote:
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....

That's fine. I assume the server has to have the file system path
accessible in order to set it up as a virtual directory to begin with,
correct?

What, then, is the format I need to pass to MapPath to get the physical
address of the virtual directory? Everything I try appends the physical
directory of my ASP.NET project to the virtual directory.

IE: I have the virtual directory set as MyVirtualDirectory, pointing to
D:\MyFiles.

My ASP.NET project lives in C:\MyProjects\Project_1

If I try Server.MapPath("MyVirtualDirectory"), I get back
C:\MyProjects\Project_1\MyVirtualDirectory.

I need to get D:\MyFiles.

What am I doing wrong?
Nov 19 '05 #7
Gave this a try and it works fine here even if relative ?

Does this physical directory exists ? If you have both a virtual and a
physical directory Server.MapPath might well favor the physical directory ?

Else double check your IIS configuration ? Is the site restarted since you
created the virtual directory ? If you type the URL in your browser can you
check if you reach the expected location ?

Good luck.

--
Patrice

"Patrice" <no****@nowhere.com> a écrit dans le message de
news:uE****************@TK2MSFTNGP10.phx.gbl...
What if you try "/MyVirtualDirectory" or "~/MyVirtualDirectory" instead ?

IMO Server.MapPath resolves the root and then add the relative path
resolving the relative path to a local directory.
Using an absolute path should hopefully solve this issue.

--
Patrice

"B Letts" <bl****@klinitek.com> a écrit dans le message de
news:ej**************@TK2MSFTNGP12.phx.gbl...
Patrice wrote:
Server.MapPath should work. What exception do you have ? Could it be a
permission issue ?


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.


Nov 19 '05 #8
Curt_C [MVP] wrote:
Try
Server.MapPath("/MyVirtualDirectory") and see what you get.


Nope. I get an InvalidOperationException if I try that.

Here's what I tried:

- Set up a Virtual Directory in IIS, called MyVirtualDirectory. It
points to C:\temp. I gave it all permissions - read write browse execute
etc.

- pointing a browser to http://localhost/MyVirtualDirectory/ gives me a
file listing of the correct directory

- My ASP.NET project that I'm trying to acccess the virtual directory is
running from C:\MyProject
Server.MapPath("MyVirtualDirectory") gives me
"C:\\MyProject\\MyVirtualDirectory"

Server.MapPath("\\MyVirtualDirectory") gives me an
InvalidOperationException

Server.MapPath("\MyVirtualDirectory") gives me an unrecognized escape
sequence (no surprise)

Server.MapPath("/MyVirtualDirectory") gives me InvalidOperationException
and also says "Failed to map the path '/MyVirtualDirectory'."}

Server.MapPath("//MyVirtualDirectory") gives me
InvalidOperationException and also says "Failed to map the path
'/MyVirtualDirectory'."}
What else can I try? Could this be a permissions and/or setup issue?
Nov 19 '05 #9
That's odd, using :

Server.MapPath("/MyVirtualDirectory") works fine for me.

Server.MapPath("/SomeOtherVirtualDirectory/") works fine, too.

Server.MapPath("/aDifferentVirtualDirectory/somefile.ext") also works.

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"B Letts" <bl****@klinitek.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Curt_C [MVP] wrote:
Try Server.MapPath("/MyVirtualDirectory") and see what you get.


Nope. I get an InvalidOperationException if I try that.

Here's what I tried:

- Set up a Virtual Directory in IIS, called MyVirtualDirectory. It points to C:\temp. I
gave it all permissions - read write browse execute etc.

- pointing a browser to http://localhost/MyVirtualDirectory/ gives me a file listing of
the correct directory

- My ASP.NET project that I'm trying to acccess the virtual directory is running from
C:\MyProject
Server.MapPath("MyVirtualDirectory") gives me "C:\\MyProject\\MyVirtualDirectory"

Server.MapPath("\\MyVirtualDirectory") gives me an InvalidOperationException

Server.MapPath("\MyVirtualDirectory") gives me an unrecognized escape sequence (no
surprise)

Server.MapPath("/MyVirtualDirectory") gives me InvalidOperationException and also says
"Failed to map the path '/MyVirtualDirectory'."}
Server.MapPath("//MyVirtualDirectory") gives me InvalidOperationException and also
says "Failed to map the path '/MyVirtualDirectory'."}

What else can I try? Could this be a permissions and/or setup issue?

Nov 19 '05 #10
Hmm very odd then.

What version of IIS/ASP.NET are you using?

Juan T. Llibre wrote:
That's odd, using :

Server.MapPath("/MyVirtualDirectory") works fine for me.

Server.MapPath("/SomeOtherVirtualDirectory/") works fine, too.

Server.MapPath("/aDifferentVirtualDirectory/somefile.ext") also works.


Nov 19 '05 #11
Is MyVirtualDirectory a different application (not under your web
application root in IIS ) ?.. if so, I think for security reasons, it will
not be possible to get path of a different application..

In IIS, MyVirtualDirectory should be like below for Server.MapPath to work

Default WebSite --
|
-- your Web Application Root --
|
--
MyVirtualDirectory

"B Letts" wrote:
Curt_C [MVP] wrote:
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....

That's fine. I assume the server has to have the file system path
accessible in order to set it up as a virtual directory to begin with,
correct?

What, then, is the format I need to pass to MapPath to get the physical
address of the virtual directory? Everything I try appends the physical
directory of my ASP.NET project to the virtual directory.

IE: I have the virtual directory set as MyVirtualDirectory, pointing to
D:\MyFiles.

My ASP.NET project lives in C:\MyProjects\Project_1

If I try Server.MapPath("MyVirtualDirectory"), I get back
C:\MyProjects\Project_1\MyVirtualDirectory.

I need to get D:\MyFiles.

What am I doing wrong?

Nov 19 '05 #12
The sample path i put in prev post was broken coz of word wrap..

Is the MyVirtualDirectory configured like Scenario 1 or 2 in IIS?

Scenario 1 ) Default WebSite -> your Web Application Root ->
MyVirtualDirectory

Scenario 2)
Default WebSite -> your Web Application Root
Default WebSite -> MyVirtualDirectory

"Sreejith Ram" wrote:
Is MyVirtualDirectory a different application (not under your web
application root in IIS ) ?.. if so, I think for security reasons, it will
not be possible to get path of a different application..

In IIS, MyVirtualDirectory should be like below for Server.MapPath to work

Default WebSite --
|
-- your Web Application Root --
|
--
MyVirtualDirectory

"B Letts" wrote:
Curt_C [MVP] wrote:
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....

That's fine. I assume the server has to have the file system path
accessible in order to set it up as a virtual directory to begin with,
correct?

What, then, is the format I need to pass to MapPath to get the physical
address of the virtual directory? Everything I try appends the physical
directory of my ASP.NET project to the virtual directory.

IE: I have the virtual directory set as MyVirtualDirectory, pointing to
D:\MyFiles.

My ASP.NET project lives in C:\MyProjects\Project_1

If I try Server.MapPath("MyVirtualDirectory"), I get back
C:\MyProjects\Project_1\MyVirtualDirectory.

I need to get D:\MyFiles.

What am I doing wrong?

Nov 19 '05 #13
The release version of ASP.NET on IIS 6.0.

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"B Letts" <bl****@klinitek.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
Hmm very odd then.

What version of IIS/ASP.NET are you using? Juan T. Llibre wrote:
That's odd, using :

Server.MapPath("/MyVirtualDirectory") works fine for me.

Server.MapPath("/SomeOtherVirtualDirectory/") works fine, too.

Server.MapPath("/aDifferentVirtualDirectory/somefile.ext") also works.

Nov 19 '05 #14
re:
Is MyVirtualDirectory a different application (not under your web
application root in IIS ) ?.. if so, I think for security reasons, it will
not be possible to get path of a different application..
Incorrect. Server.MapPath *does* work from different Applications.


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Sreejith Ram" <Sr*********@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com... Is MyVirtualDirectory a different application (not under your web
application root in IIS ) ?.. if so, I think for security reasons, it will
not be possible to get path of a different application..

In IIS, MyVirtualDirectory should be like below for Server.MapPath to work

Default WebSite --
|
-- your Web Application Root -- | -- MyVirtualDirectory

"B Letts" wrote:

Curt_C [MVP] wrote:
> 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....
>
>

That's fine. I assume the server has to have the file system path
accessible in order to set it up as a virtual directory to begin with,
correct?

What, then, is the format I need to pass to MapPath to get the physical
address of the virtual directory? Everything I try appends the physical
directory of my ASP.NET project to the virtual directory.

IE: I have the virtual directory set as MyVirtualDirectory, pointing to
D:\MyFiles.

My ASP.NET project lives in C:\MyProjects\Project_1

If I try Server.MapPath("MyVirtualDirectory"), I get back
C:\MyProjects\Project_1\MyVirtualDirectory.

I need to get D:\MyFiles.

What am I doing wrong?

Nov 19 '05 #15
I've tried it both ways. Neither works.

Sreejith Ram wrote:
The sample path i put in prev post was broken coz of word wrap..

Is the MyVirtualDirectory configured like Scenario 1 or 2 in IIS?

Scenario 1 ) Default WebSite -> your Web Application Root ->
MyVirtualDirectory

Scenario 2)
Default WebSite -> your Web Application Root
Default WebSite -> MyVirtualDirectory

Nov 19 '05 #16
you are right.. it works with syntax Server.MapPath("/MyVirtualDirectory") ,
even if a diffrent application..

Thanks for correcting..

"Juan T. Llibre" wrote:
re:
Is MyVirtualDirectory a different application (not under your web
application root in IIS ) ?.. if so, I think for security reasons, it will
not be possible to get path of a different application..


Incorrect. Server.MapPath *does* work from different Applications.


Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Sreejith Ram" <Sr*********@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
Is MyVirtualDirectory a different application (not under your web
application root in IIS ) ?.. if so, I think for security reasons, it will
not be possible to get path of a different application..

In IIS, MyVirtualDirectory should be like below for Server.MapPath to work

Default WebSite --
|
-- your Web Application Root --

|
-- MyVirtualDirectory

"B Letts" wrote:

Curt_C [MVP] wrote:
> 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....
>
>
That's fine. I assume the server has to have the file system path
accessible in order to set it up as a virtual directory to begin with,
correct?

What, then, is the format I need to pass to MapPath to get the physical
address of the virtual directory? Everything I try appends the physical
directory of my ASP.NET project to the virtual directory.

IE: I have the virtual directory set as MyVirtualDirectory, pointing to
D:\MyFiles.

My ASP.NET project lives in C:\MyProjects\Project_1

If I try Server.MapPath("MyVirtualDirectory"), I get back
C:\MyProjects\Project_1\MyVirtualDirectory.

I need to get D:\MyFiles.

What am I doing wrong?


Nov 19 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dennis | last post by:
Hi, I have a doubt about uploading ASP.NET web application from development computer to web server. Is there any way to store the ASP.NET web application in the server's virtual directory that...
10
by: Wm. Scott Miller | last post by:
We have a intranet site that allows one of our departments to search a set of pdfs and then look at them. Only problem is that only they and us geeks should be allowed to see the pdfs. We have it...
0
by: Support | last post by:
I've a problem while creating web setup project using "Setup & Deployment Projects" (for Web projects/Web setup). The following steps I followed while doing so. 1. Created a web setup project...
1
by: Joel Zinn | last post by:
I am having to change several websites that upload files. Our web master has changed the replication tool and that is causing a problem. We have been using the normal httpInputFile object. It...
1
by: Pgar | last post by:
I have a page that I have the users uploading files from their local machines. I take these files strip off their path and redirect it to a new file on the web server. I have a virtual directory...
2
by: dhnriverside | last post by:
Hi I've got a web app that I've installed on a client computer. Basically it's an intranet, and has a section where staff can upload media files for all to see, so theyre all in a conveinient...
2
by: BLetts | last post by:
I have an ASP.NET app that must allow users to upload files. The files are stored in a virtual directory. I use Server.MapPath to map from the virtual directory name to a physical path, then the...
8
by: Nate | last post by:
I am running on Window 2003. I have a website built in ASP.NET 2.0. I need to have a Virtual Directory running an application in 1.1. I have configured each in its own Application Pool. The 1.1...
5
by: Ned White | last post by:
I have set up a virtual directory on ISS 6.0 to store the all .jpg and .swf files which i use in my project It is alias name is "OutSrc" Is it possible to acquire a list of files which exist in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.