473,804 Members | 2,711 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Server.MapPath Failed to map the path error

The below code is what I'm using to upload JPG's to a Shared folder on
my web server. The folder \\GLSDBS03\Entr y$ is outside my Web folder.
When using FileUpload, and trying to save the JPG, I get a "Failed to
map the path '/GLSDBS03/Entry$'" error. I'm open to suggestions or a
better idea.

Thanks

*************** *************** ***************

public partial class ImageUpload : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath( "\\\\GLSDBS03\\ Entry$");
if (FileUpload1.Ha sFile)
{
String fileExtension =

System.IO.Path. GetExtension(Fi leUpload1.FileN ame).ToLower();
String[] allowedExtensio ns =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensio ns.Length; i++)
{
if (fileExtension == allowedExtensio ns[i])
{
fileOK = true;
}
}
}

if (fileOK)
{
try
{
FileUpload1.Pos tedFile.SaveAs( path +
FileUpload1.Fil eName);
ListBox1.Items. Add(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.";
}
}
else
{
DirectoryInfo di = new
DirectoryInfo(" \\\\GLSDBS03\\E ntry$");
try
{
// Determine whether the directory exists.
if (di.Exists)
{
FileInfo[] files = di.GetFiles();
for (int i = 0; i < files.Length; i++)
{
ListBox1.Items. Add(files[i].Name);
}
}
}
finally { }
}
}
}

Dec 19 '06 #1
4 5641
Hi,

Well; to what you expect ot have that UNC maped to?
The idea of "mapping" is that from a web app you have a relative path like
/myfolder or / and if you need to use File methods you need the real path of
those folders, so in that case / could be traslated to c:\inetpub\www\ app1

\\GLS.... is already a global path, you do not need to map it to nothing.

The only problem you will have is of permissions. usually a web app cannot
access nothing outside its root path. For obvious security options.

you may need to map your path under IIS
--
Ignacio Machin
machin AT laceupsolutions com

"Dave" <Ki************ @Verizon.Netwro te in message
news:11******** *************@8 0g2000cwy.googl egroups.com...
The below code is what I'm using to upload JPG's to a Shared folder on
my web server. The folder \\GLSDBS03\Entr y$ is outside my Web folder.
When using FileUpload, and trying to save the JPG, I get a "Failed to
map the path '/GLSDBS03/Entry$'" error. I'm open to suggestions or a
better idea.

Thanks

*************** *************** ***************

public partial class ImageUpload : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath( "\\\\GLSDBS03\\ Entry$");
if (FileUpload1.Ha sFile)
{
String fileExtension =

System.IO.Path. GetExtension(Fi leUpload1.FileN ame).ToLower();
String[] allowedExtensio ns =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensio ns.Length; i++)
{
if (fileExtension == allowedExtensio ns[i])
{
fileOK = true;
}
}
}

if (fileOK)
{
try
{
FileUpload1.Pos tedFile.SaveAs( path +
FileUpload1.Fil eName);
ListBox1.Items. Add(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.";
}
}
else
{
DirectoryInfo di = new
DirectoryInfo(" \\\\GLSDBS03\\E ntry$");
try
{
// Determine whether the directory exists.
if (di.Exists)
{
FileInfo[] files = di.GetFiles();
for (int i = 0; i < files.Length; i++)
{
ListBox1.Items. Add(files[i].Name);
}
}
}
finally { }
}
}
}

Dec 19 '06 #2
Ignacio,
Thanks for your reply. This is where it gets confusing. The
DirectoryInfo line below works fine. Also, the \\GLS address is to a
shared drive, so I'm still a bit at a loss.

A bit more history. The reason why the folder is out root path is so
that it doesn't get over written if/when changes are made to the web
site. The folder contains employee pictures.

In mapping the folder under IIS, if I understand you correctly, you're
suggesting that I set it up with it's own http://?
Thanks for your time

Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,

Well; to what you expect ot have that UNC maped to?
The idea of "mapping" is that from a web app you have a relative path like
/myfolder or / and if you need to use File methods you need the real path of
those folders, so in that case / could be traslated to c:\inetpub\www\ app1

\\GLS.... is already a global path, you do not need to map it to nothing.

The only problem you will have is of permissions. usually a web app cannot
access nothing outside its root path. For obvious security options.

you may need to map your path under IIS
--
Ignacio Machin
machin AT laceupsolutions com

"Dave" <Ki************ @Verizon.Netwro te in message
news:11******** *************@8 0g2000cwy.googl egroups.com...
The below code is what I'm using to upload JPG's to a Shared folder on
my web server. The folder \\GLSDBS03\Entr y$ is outside my Web folder.
When using FileUpload, and trying to save the JPG, I get a "Failed to
map the path '/GLSDBS03/Entry$'" error. I'm open to suggestions or a
better idea.

Thanks

*************** *************** ***************

public partial class ImageUpload : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath( "\\\\GLSDBS03\\ Entry$");
if (FileUpload1.Ha sFile)
{
String fileExtension =

System.IO.Path. GetExtension(Fi leUpload1.FileN ame).ToLower();
String[] allowedExtensio ns =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensio ns.Length; i++)
{
if (fileExtension == allowedExtensio ns[i])
{
fileOK = true;
}
}
}

if (fileOK)
{
try
{
FileUpload1.Pos tedFile.SaveAs( path +
FileUpload1.Fil eName);
ListBox1.Items. Add(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.";
}
}
else
{
DirectoryInfo di = new
DirectoryInfo(" \\\\GLSDBS03\\E ntry$");
try
{
// Determine whether the directory exists.
if (di.Exists)
{
FileInfo[] files = di.GetFiles();
for (int i = 0; i < files.Length; i++)
{
ListBox1.Items. Add(files[i].Name);
}
}
}
finally { }
}
}
}
Dec 20 '06 #3
Got it! In IIS, at the web site, create a New Virtual Directory
pointing to the folder. At that point it makes it as part of the root.
Thanks Ignacio!

Dave wrote:
Ignacio,
Thanks for your reply. This is where it gets confusing. The
DirectoryInfo line below works fine. Also, the \\GLS address is to a
shared drive, so I'm still a bit at a loss.

A bit more history. The reason why the folder is out root path is so
that it doesn't get over written if/when changes are made to the web
site. The folder contains employee pictures.

In mapping the folder under IIS, if I understand you correctly, you're
suggesting that I set it up with it's own http://?
Thanks for your time

Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,

Well; to what you expect ot have that UNC maped to?
The idea of "mapping" is that from a web app you have a relative path like
/myfolder or / and if you need to use File methods you need the real path of
those folders, so in that case / could be traslated to c:\inetpub\www\ app1

\\GLS.... is already a global path, you do not need to map it to nothing.

The only problem you will have is of permissions. usually a web app cannot
access nothing outside its root path. For obvious security options.

you may need to map your path under IIS
--
Ignacio Machin
machin AT laceupsolutions com

"Dave" <Ki************ @Verizon.Netwro te in message
news:11******** *************@8 0g2000cwy.googl egroups.com...
The below code is what I'm using to upload JPG's to a Shared folder on
my web server. The folder \\GLSDBS03\Entr y$ is outside my Web folder.
When using FileUpload, and trying to save the JPG, I get a "Failed to
map the path '/GLSDBS03/Entry$'" error. I'm open to suggestions or a
better idea.
>
Thanks
>
*************** *************** ***************
>
public partial class ImageUpload : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath( "\\\\GLSDBS03\\ Entry$");
if (FileUpload1.Ha sFile)
{
String fileExtension =
>
System.IO.Path. GetExtension(Fi leUpload1.FileN ame).ToLower();
String[] allowedExtensio ns =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensio ns.Length; i++)
{
if (fileExtension == allowedExtensio ns[i])
{
fileOK = true;
}
}
}
>
if (fileOK)
{
try
{
FileUpload1.Pos tedFile.SaveAs( path +
FileUpload1.Fil eName);
ListBox1.Items. Add(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.";
}
}
else
{
DirectoryInfo di = new
DirectoryInfo(" \\\\GLSDBS03\\E ntry$");
try
{
// Determine whether the directory exists.
if (di.Exists)
{
FileInfo[] files = di.GetFiles();
for (int i = 0; i < files.Length; i++)
{
ListBox1.Items. Add(files[i].Name);
}
}
}
finally { }
}
}
}
>
Dec 20 '06 #4
Got it! In IIS, at the web site, create a New Virtual Directory
pointing to the folder. At that point it makes it as part of the root.
Thanks Ignacio!

Dave wrote:
Ignacio,
Thanks for your reply. This is where it gets confusing. The
DirectoryInfo line below works fine. Also, the \\GLS address is to a
shared drive, so I'm still a bit at a loss.

A bit more history. The reason why the folder is out root path is so
that it doesn't get over written if/when changes are made to the web
site. The folder contains employee pictures.

In mapping the folder under IIS, if I understand you correctly, you're
suggesting that I set it up with it's own http://?
Thanks for your time

Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,

Well; to what you expect ot have that UNC maped to?
The idea of "mapping" is that from a web app you have a relative path like
/myfolder or / and if you need to use File methods you need the real path of
those folders, so in that case / could be traslated to c:\inetpub\www\ app1

\\GLS.... is already a global path, you do not need to map it to nothing.

The only problem you will have is of permissions. usually a web app cannot
access nothing outside its root path. For obvious security options.

you may need to map your path under IIS
--
Ignacio Machin
machin AT laceupsolutions com

"Dave" <Ki************ @Verizon.Netwro te in message
news:11******** *************@8 0g2000cwy.googl egroups.com...
The below code is what I'm using to upload JPG's to a Shared folder on
my web server. The folder \\GLSDBS03\Entr y$ is outside my Web folder.
When using FileUpload, and trying to save the JPG, I get a "Failed to
map the path '/GLSDBS03/Entry$'" error. I'm open to suggestions or a
better idea.
>
Thanks
>
*************** *************** ***************
>
public partial class ImageUpload : System.Web.UI.P age
{
protected void Page_Load(objec t sender, EventArgs e)
{
if (IsPostBack)
{
Boolean fileOK = false;
String path = Server.MapPath( "\\\\GLSDBS03\\ Entry$");
if (FileUpload1.Ha sFile)
{
String fileExtension =
>
System.IO.Path. GetExtension(Fi leUpload1.FileN ame).ToLower();
String[] allowedExtensio ns =
{ ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensio ns.Length; i++)
{
if (fileExtension == allowedExtensio ns[i])
{
fileOK = true;
}
}
}
>
if (fileOK)
{
try
{
FileUpload1.Pos tedFile.SaveAs( path +
FileUpload1.Fil eName);
ListBox1.Items. Add(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.";
}
}
else
{
DirectoryInfo di = new
DirectoryInfo(" \\\\GLSDBS03\\E ntry$");
try
{
// Determine whether the directory exists.
if (di.Exists)
{
FileInfo[] files = di.GetFiles();
for (int i = 0; i < files.Length; i++)
{
ListBox1.Items. Add(files[i].Name);
}
}
}
finally { }
}
}
}
>
Dec 20 '06 #5

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

Similar topics

7
14382
by: A P | last post by:
I receive an error like this: Server.MapPath() error 'ASP 0172 : 80004005' Invalid Path /conn.asp, line 2 The Path parameter for the MapPath method must be a virtual path. A physical path was used.
0
1891
by: awbacker | last post by:
Havin a problem with MapPath() failing on me. It doesn't do it right away, but at some point it dies and won't come back. I have to hiccup the app by poking IIS or a web.config/other critical file. First, some background : 0. .Net 1.1, Win2k, IIS5 w/ UrlScan (etc). Basic barebones win2k webserver. 1. This just started happening recently. This area of the code has not changed a bit since the last update, and has been functioning...
3
3989
by: Cozmo | last post by:
We have an .asp application , located in: e:\myapp In there we have directories like: e:\myapp\db e:\myapp\images e:\myapp\utils e:\myapp\working
7
3396
by: benoit | last post by:
Hi, if I write this code to retrieve a folder on the server Server.mappath("/DATA") I get this error message System.InvalidOperationException: Failed to map the path '/DATA' the virtual folder for my webApp is not situated in Inetpub, nor is the DATA folder that I would like to retrieve
0
1875
by: lknight643 | last post by:
I have an asp.net application that works with a SQL server database on server No. 1 but I want to upload files for storage to Server No. 2 that is accessible only from the Internet. If the file storage was on server No. 1, I would specify a physical file path (ChosenDirectory) for storage of the uploaded file but in my case I need to specify a virtual path like http://server2/folder1/. I'm trying to use server.mappath to convert the...
14
12733
by: Lorenzo | last post by:
Hello, I have a web application with a virtual directory in it. With 'virtual directory' i mean a folder whose physical path is different from the physical path of the application, but in which Web Sharing is active. For example: my application is in "C:\Inetpub\wwwroot\MyApp", the Virtual folder is in "C:\VirtualFolder", and IIS sees it as if it were in "C:\Inetpub\wwwroot\MyApp\VirtualFolder".
5
9628
by: MichiMichi | last post by:
When using Server.MapPath on IIS 5 on my localhost everything works well. All of the following commands are executed without any error Response.Write(Server.MapPath("/app_test") & "<br>") Response.Write(Server.MapPath("app_test") & "<br>") Response.Write(Server.MapPath("~") & "<br>") However, running the first statement on via the internal Visual Studio 2005 Server I receive an error for
4
7195
by: vunet.us | last post by:
How to use server.mappath() parent folder correctly: Server.MapPath("../test.asp") Thank you for the hint.
3
4136
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have one line code in my program, occasionaly I will receive the following error: "The Path parameter for the MapPath method did not correspond to a known path" Path=Server.MapPath(sCertPath & "\" & order_id & ".pdf") I am wondering what is happening since every time I check my error log, the
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10561
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
10318
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
10302
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
10069
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
7608
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
6845
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
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3803
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.