473,382 Members | 1,447 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,382 software developers and data experts.

Server.MapPath

ats
Hi there. I have a folder named reports on my web server. Inside the folder
is a page named reports.aspx and 2 folders named client1 and client2. I
have some spreadsheets in each of the folders that are relative to each
individual client. I would like to know how I can use server.mappath to
choose the correct folder depending on which client is logged. For example
I would have the following code on my page behind:

<CODE>
Dim dirReo as New DirectoryInfo

Select case client
case client 1
dirInfo = Server.MapPath(???)

case client 2
dirInfo = Server.MapPath(???)

end select

reportList.DataSource = dirInfo.GetFiles("*.xls")
reportList.DataBind
<END CODE

What do I need to put in the brackets to replace the ???
--
ats@jbex

When an old lady got hit by a truck
I saw the wicked gleam in your eyes

Adam and The Ants - Whip In My Valise
Feb 7 '08 #1
1 2681
You can use the tilde character ("~") to specify the root of you
rapplication. For example, if your reports folder is located at the root
level of your app, you could use Server.MapPath("~/reports/client1") which
will return a string representation of the physical path (i.e.,
"C:\inetpub\wwwroot", etc) to the folder specified.

You could then use a DirectoryInfo object to find the files you are looking
for.

Example Code:

Dim pathToFolder as String = Server.MapPath("~/reports/" & client)

Dim d As DirectoryInfo = New DirectoryInfo(pathToFolder)
d.GetFiles("*.xls")
"ats@jbex" wrote:
Hi there. I have a folder named reports on my web server. Inside the folder
is a page named reports.aspx and 2 folders named client1 and client2. I
have some spreadsheets in each of the folders that are relative to each
individual client. I would like to know how I can use server.mappath to
choose the correct folder depending on which client is logged. For example
I would have the following code on my page behind:

<CODE>
Dim dirReo as New DirectoryInfo

Select case client
case client 1
dirInfo = Server.MapPath(???)

case client 2
dirInfo = Server.MapPath(???)

end select

reportList.DataSource = dirInfo.GetFiles("*.xls")
reportList.DataBind
<END CODE

What do I need to put in the brackets to replace the ???
--
ats@jbex

When an old lady got hit by a truck
I saw the wicked gleam in your eyes

Adam and The Ants - Whip In My Valise
Feb 7 '08 #2

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

Similar topics

13
by: John Rebbeck | last post by:
I've got the directory f:\Company\Product set as web shared so it's got a virtual directory in the default web site on my test server's IIS. If I try to use Server.MapPath in that site it returns a...
4
by: Laphan | last post by:
Hi All Sorry to be irate, but the whole concept of Server.MapPaths really has me in a tiswas!! In order to confirm once and for all, could you please advise me on the following: 1) There...
6
by: darrel | last post by:
I have some functions that are reading/writing to the file system. As such, they use server.mapPath a lot to navigate it all. Since I'm using these functions numerous times throughout my...
7
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...
14
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...
5
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>")...
4
by: vunet.us | last post by:
How to use server.mappath() parent folder correctly: Server.MapPath("../test.asp") Thank you for the hint.
3
by: rn5a | last post by:
Server.MapPath returns the physical file path that corresponds to the specified virtual path whereas Request.MapPath maps the specified virtual path to a physical path. Assuming that a file named...
6
by: withers | last post by:
If I run Server.MapPath("/") on my operational Internet server I get, correctly, the physical path to the directory my page is in (d:\.... \...\htdocs). If I run Server.MapPath("/") on my...
3
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" ...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.