Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 22nd, 2007, 02:19 PM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can't access local file in App_Data folder

Hi all:

This has got to be a simple no-brainer, but has me stumped for 2 days.

I have a .txt file in my website's App_Data folder that I need to open and read/write inter-eactively while a user is accessing the site. In production the entire website including this file will live at the server.

I have not been able to find a way to get programmable access to the file and that's the problem.

1. There is no App.Path available.
2. CurPath points to the IDE, not the app's child files.
3. Using a tilde in a path string does not work.
4. Using the file name in a path string does not work either.
5. I've tried, File, FileInfo, Directory, Drive, DriveInfo objects.
   Nothing works.

Anyone have a suggestion on how to read/write progrmmatically to this asp.net 2 website app file?

Thanks for your ideas.

VictorVictor



  #2 (permalink)  
Old January 22nd, 2007, 02:26 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. I cann't find an example here.. but did you try with server.mappath??

you can use that to get the actual path to a file doing something like:

server.mappath("app_data")

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
  #3 (permalink)  
Old January 22nd, 2007, 02:56 PM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Gonzalo:

Thanks for the idea.

I tried your suggestion and got an error message as follows:
'server.mappath' is not declared or the module containing it is not loaded in the debugging path.

Basically what I did was put a breakpoint on a line of code in the code module (web page) where I need to read that file, and then asked the Immediate Debugging window to show me what server.mappath had in it.

VV


  #4 (permalink)  
Old January 22nd, 2007, 03:22 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

well.. you can access the server object directly from a web page, but not inside a module...
if you want that, you have to pass the server object to the function in the module...

I understood you right????

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
  #5 (permalink)  
Old January 22nd, 2007, 04:35 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Alternatively, you can use

HttpContext.Current.Session in your modules / classes.

http://www.syncfusion.com/FAQ/aspnet/WEB_c9c.aspx#q244q

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #6 (permalink)  
Old January 22nd, 2007, 11:24 PM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Gonzalo: Thanks for the update. Yes you understand correctly. I was hoping for a simple answer -- not always possible. I'll have to look further into passing access to the httpcontext object from an aspx page to a class instance object. Exactly how to do that is the problem.

Imar: Thanks too. I have spent over 3 hours with my app's httpcontext object, the current object and the session object and a large number of all these objects' properties. Still no joy.

This is such a simple thing and tons of developers must have been here before. I'm perplexed as to why this is giving me such a problem.

VV


  #7 (permalink)  
Old January 22nd, 2007, 11:29 PM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A bit more about this problem. I can think of several ways AROUND the problem. For example, an xml file as a local resource, a fixed array, a class. There are many more ways, but I wish to find a way to access a simple .txt file in the site's App_Data folder (or some other app folder) because there will be times in the future and other apps where the same problem will come up. VV


  #8 (permalink)  
Old January 23rd, 2007, 02:32 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I said Session, but I meant Server. Sorry.... ;)

Can you post the relevant bits of code and describe the site's structure? E.g. where you call this code, where its class file resides and so on.

This should just work as expected....

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #9 (permalink)  
Old January 23rd, 2007, 10:15 AM
Friend of Wrox
 
Join Date: Apr 2005
Location: Fort Walton Beach, FL, USA.
Posts: 190
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar and Gonzalo:

Thanks guys for the help. Problem solved.

Below is a small VB function that uses the current httpcontext properties to get a path to a website file containing the .txt file I need to read. The nice thing about the line using the httpcontext is that it will work wherever on the server, the file winds up.

The purpose of the function is to test that a naughty user does not enter a nasty word in an input text field. I have more functions in a class to test for more bad input, this is for just the nasty words possibility.

    Public Function IsBadWord(ByVal sWord As String) As Boolean
        Dim bReturnValue As Boolean = False
        Dim sBadWordsFilePath As String
        sBadWordsFilePath = HttpContext.Current.ApplicationInstance.Server.Map Path("~/App_Data/BadWords.txt")
        Dim reader As StreamReader = New StreamReader(sBadWordsFilePath)
        Try
            Do
                If reader.ReadLine = sWord Then
                    bReturnValue = True
                    Exit Do
                End If
            Loop Until reader.Peek = -1
        Catch ex As Exception

        Finally
            reader.Close()
        End Try
        Return bReturnValue
    End Function
------------------------
Thanks again.

VictorVictor


 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is the "Local Drafts Folder" btracy BOOK: Beginning SharePoint 2007: Building Team Solutions with MOSS 2007 ISBN: 978-0-470-12449-9 2 June 28th, 2010 02:20 PM
local folder location euschenk Classic ASP Basics 3 March 5th, 2008 04:46 PM
help...copy files from sharepoint to local folder pinkflakes .NET Web Services 0 November 3rd, 2007 10:02 PM
How can i import a local text file into a jsp file ravibabu Java GUI 1 April 25th, 2007 04:05 AM



All times are GMT -4. The time now is 12:03 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.