473,503 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VS2005 - how to specify location of a text file in dev and production?

dgk
I have a few text files that I read in at run time into label
controls; they're stored in a Text folder in the app. At run time I
try to read them in by using "~/text/thefile.txt" but it doesn't work
in the editor or when published. I've tried a few appgetpath type
things and can't get one to work.

Any help greatly appreciated.
Mar 18 '07 #1
5 985
The "~" syntax is inderstood by aspx pages only. Try just
MapPath("text/thefile.txt").

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"dgk" <No*****@MailsAnonymous.comwrote in message
news:rp********************************@4ax.com...
>I have a few text files that I read in at run time into label
controls; they're stored in a Text folder in the app. At run time I
try to read them in by using "~/text/thefile.txt" but it doesn't work
in the editor or when published. I've tried a few appgetpath type
things and can't get one to work.

Any help greatly appreciated.

Mar 18 '07 #2
dgk
On Sun, 18 Mar 2007 10:26:38 +0200, "Eliyahu Goldin"
<RE**************************@mMvVpPsS.orgwrote:
>The "~" syntax is inderstood by aspx pages only. Try just
MapPath("text/thefile.txt").
Yes, that works. Thanks.
Mar 18 '07 #3
I use this function:
I find it easier to wrap this up in a function for maintenance , debugging
and consistency issues.
Its probably a little overkill, but I'm come to trust it, for than random
MapPaths all over the place.


public static string FindPhysicalRootDirectory(Page p)
{
string rootDir;
rootDir = p.Server.MapPath("~/");
return rootDir;
}


Public Shared Function FindPhysicalRootDirectory(ByVal p As Page) As
String

Dim rootDir As String

rootDir = p.Server.MapPath("~/")

Return rootDir

End Function
I have another counter part:

public static string FindVirtualRootDirectory(Page p)
{
return "~/";
}

It seems to work.
Remember , in 2.0 remember to test against IIS deployment and the casino web
server deployment. (the local non iis port-number deployment)

If you wait to test IIS until deployment, you may be surprised it doesn't
work.

"dgk" <No*****@MailsAnonymous.comwrote in message
news:rp********************************@4ax.com...
I have a few text files that I read in at run time into label
controls; they're stored in a Text folder in the app. At run time I
try to read them in by using "~/text/thefile.txt" but it doesn't work
in the editor or when published. I've tried a few appgetpath type
things and can't get one to work.

Any help greatly appreciated.

Mar 19 '07 #4
dgk
On Mon, 19 Mar 2007 10:30:47 -0400, "sloan" <sl***@ipass.netwrote:
Public Shared Function FindPhysicalRootDirectory(ByVal p As Page) As
String

Dim rootDir As String

rootDir = p.Server.MapPath("~/")

Return rootDir

End Function
Thanks, I select this one being a VB guy. But is there some reason not
to just do:

Dim rootDir as String = p.Server.MapPath("~/")

or even just

Return p.Server.MapPath("~/")
I'm not sure what any of them get you over just throwing MapPath("~/")
into the code?
Mar 20 '07 #5

Did you test against

IIS vs Casino deployment?

"dgk" <dg*@somewhere.comwrote in message
news:8h********************************@4ax.com...
On Mon, 19 Mar 2007 10:30:47 -0400, "sloan" <sl***@ipass.netwrote:
Public Shared Function FindPhysicalRootDirectory(ByVal p As Page) As
String

Dim rootDir As String

rootDir = p.Server.MapPath("~/")

Return rootDir

End Function

Thanks, I select this one being a VB guy. But is there some reason not
to just do:

Dim rootDir as String = p.Server.MapPath("~/")

or even just

Return p.Server.MapPath("~/")
I'm not sure what any of them get you over just throwing MapPath("~/")
into the code?

Mar 20 '07 #6

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

Similar topics

0
2639
by: Don Stevic | last post by:
I am running VS2005 and using VSTO for Word. I keep getting this error saying that there is no source code available for this location when I try and run this application. I am going to...
2
2102
by: David Hearn | last post by:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Description: An unhandled exception occurred during the execution of the current...
0
321
by: Don Stevic | last post by:
I am running VS2005 and using VSTO for Word. I keep getting this error saying that there is no source code available for this location when I try and run this application. I am going to...
15
4190
by: Joseph Geretz | last post by:
OK, I'll admit it up front - I just don't get it. Here's our previous VS2003 development model. Developers develop the WS solution on their own workstations, using their own IIS web servers...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
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...
1
6988
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...
0
7456
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...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5011
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...
0
4672
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...
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.