Server.MapPath

A

ats@jbex

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
 
R

rowe_newsgroups

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

I would use String.Format to put in the name of the current user into
the Server.MapPath code.

i.e.

///////////////
Dim path as String = Server.MapPath("../Reports/{0}/",
Page.User.Identity.Name)
//////////////

Thanks,

Seth Rowe [MVP]
 
A

ats@jbex

I would use String.Format to put in the name of the current user into
the Server.MapPath code.

i.e.

///////////////
Dim path as String = Server.MapPath("../Reports/{0}/",
Page.User.Identity.Name)
//////////////

Thanks,

Seth Rowe [MVP]

Thanks. That worked a treat :)
--
ats@jbex

But I learned to burn that bridge and delete
Those who compete...at a level that's obsolete
Instead I warm my hands upon the flames of the flag
As I recall our downfall
And the business that burned us all
See through the news and the views that twist reality

Rage Against The Machine - Bombtrack
 
C

Cyborgx37

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")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Email Archive program 12
Last Friday of each month 3
int.TryParse 9
Reformat Number on Databinding 1

Top