473,748 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Save As, 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.Save As, or an alternative method to
upload/delete files to and from a virtual directory?

Thanks in advance.
Nov 19 '05 #1
16 11792
Server.MapPath should work. What exception do you have ? Could it be a
permission issue ?

--
Patrice

"B Letts" <bl****@klinite k.com> a écrit dans le message de
news:uE******** ******@TK2MSFTN GP12.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.Save As, 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.Save As, 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.Save As, 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.Save As, 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
MyVirtualDirect ory and it points to d:\MyFiles.

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

Server.MapPath( "MyVirtualDirec tory")

It returns my current application physical directory with
"MyVirtualDirec tory" appended on the end, for example,
"C:\MyASPNETPro jects\ThisProje ct\MyVirtualDir ectory"

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 "/MyVirtualDirect ory" or "~/MyVirtualDirect ory" 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****@klinite k.com> a écrit dans le message de
news:ej******** ******@TK2MSFTN GP12.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
MyVirtualDirect ory and it points to d:\MyFiles.

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

Server.MapPath( "MyVirtualDirec tory")

It returns my current application physical directory with
"MyVirtualDirec tory" appended on the end, for example,
"C:\MyASPNETPro jects\ThisProje ct\MyVirtualDir ectory"

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( "/MyVirtualDirect ory") 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
MyVirtualDirect ory and it points to d:\MyFiles.

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

Server.MapPath( "MyVirtualDirec tory")

It returns my current application physical directory with
"MyVirtualDirec tory" appended on the end, for example,
"C:\MyASPNETPro jects\ThisProje ct\MyVirtualDir ectory"

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 MyVirtualDirect ory, pointing to
D:\MyFiles.

My ASP.NET project lives in C:\MyProjects\P roject_1

If I try Server.MapPath( "MyVirtualDirec tory"), I get back
C:\MyProjects\P roject_1\MyVirt ualDirectory.

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******** ********@TK2MSF TNGP10.phx.gbl. ..
What if you try "/MyVirtualDirect ory" or "~/MyVirtualDirect ory" 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****@klinite k.com> a écrit dans le message de
news:ej******** ******@TK2MSFTN GP12.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
MyVirtualDirect ory and it points to d:\MyFiles.

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

Server.MapPath( "MyVirtualDirec tory")

It returns my current application physical directory with
"MyVirtualDirec tory" appended on the end, for example,
"C:\MyASPNETPro jects\ThisProje ct\MyVirtualDir ectory"

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( "/MyVirtualDirect ory") and see what you get.


Nope. I get an InvalidOperatio nException if I try that.

Here's what I tried:

- Set up a Virtual Directory in IIS, called MyVirtualDirect ory. 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( "MyVirtualDirec tory") gives me
"C:\\MyProject\ \MyVirtualDirec tory"

Server.MapPath( "\\MyVirtualDir ectory") gives me an
InvalidOperatio nException

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

Server.MapPath( "/MyVirtualDirect ory") gives me InvalidOperatio nException
and also says "Failed to map the path '/MyVirtualDirect ory'."}

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

Server.MapPath( "/MyVirtualDirect ory") works fine for me.

Server.MapPath( "/SomeOtherVirtua lDirectory/") works fine, too.

Server.MapPath( "/aDifferentVirtu alDirectory/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****@klinite k.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Curt_C [MVP] wrote:
Try Server.MapPath( "/MyVirtualDirect ory") and see what you get.


Nope. I get an InvalidOperatio nException if I try that.

Here's what I tried:

- Set up a Virtual Directory in IIS, called MyVirtualDirect ory. 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( "MyVirtualDirec tory") gives me "C:\\MyProject\ \MyVirtualDirec tory"

Server.MapPath( "\\MyVirtualDir ectory") gives me an InvalidOperatio nException

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

Server.MapPath( "/MyVirtualDirect ory") gives me InvalidOperatio nException and also says
"Failed to map the path '/MyVirtualDirect ory'."}
Server.MapPath( "//MyVirtualDirect ory") gives me InvalidOperatio nException and also
says "Failed to map the path '/MyVirtualDirect ory'."}

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

Nov 19 '05 #10

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

Similar topics

1
1403
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 is different from the virtual directory that I used during development? For example, I used "http://localhost/abc" in development computer and I would like to store the application in "http://10.1.1.1/xyz" in server. The error occurs when...
10
3657
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 locked down except for when a person directly types in the url to a pdf. Currently, the PDFs are in a virtual directory off the root of the server. Putting it under the search site also doesn't work. My understanding is that IIS looks as the...
0
1067
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 in .Net and 2. Added a Programs File Folder under the File System on Target Machine. 3. Mapped all my project folders to Programs File Folder.
1
1796
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 works great, as long as you have a direct path ("c:\temp\uploads"), but it does not work well with virtual paths (http:\\AppName\Uploads). The problem is that the physical folder is not under the root app path, it has to be in another physical...
1
5415
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 mapped to a remote machine that has files in it named for the years for items that the users are uploading supporting documents (i.e. 2003, 2004, etc.) I want to check to see if the folder for a specific year exists in the Virtual Directory. Is...
2
1258
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 place. Problem is, they want to store the media files on a diff directory, one that is OUTSIDE of the website itself. They actually want a seperate drive. I've created a virtual directory in IIS to point to that, and files are
2
2613
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 FileUpload control SaveAs method to upload and save the file. This all works fine when the virtual directory points to a local drive on the ASP.NET server. However, when pointing to a remote drive (which is what my client wants to do), I get...
8
2539
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 application picks up and parses the 2.0 web.config. It is complaining about the connectionstrings node. If I comment out that node the applications both run. I have tried running the 1.1 application under 2.0 but there are some controls used in...
5
7267
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 that virtual directory ? For my default project directory, i can get list of the specific files like that; *******************
0
9552
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9326
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4877
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.