Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Using server.mappath in classes (or not)

Using server.mappath in classes (or not)

Scheduled Pinned Locked Moved ASP.NET
questionsysadminxml
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fred_Smith
    wrote on last edited by
    #1

    I can use Server.MapPath to find and read from files on my server; however I can only do this from within the code-behind for a web-page and not a separate class which gets compiled into the application dll. if I have function within this class/dll that wants to read from an xml file located in the same /bin folder, how do I do it? Is it just a matter of the right import statement in the class, or do I need to use another method altogether? OK, I could use server.mappath before calling the function and pass the full path as a parameter, but apart from that... thanks Fred

    I 1 Reply Last reply
    0
    • F Fred_Smith

      I can use Server.MapPath to find and read from files on my server; however I can only do this from within the code-behind for a web-page and not a separate class which gets compiled into the application dll. if I have function within this class/dll that wants to read from an xml file located in the same /bin folder, how do I do it? Is it just a matter of the right import statement in the class, or do I need to use another method altogether? OK, I could use server.mappath before calling the function and pass the full path as a parameter, but apart from that... thanks Fred

      I Offline
      I Offline
      iamrashida83
      wrote on last edited by
      #2

      use using System.IO; // for C# Imports System.IO // for VB.NET and then try using Server.MapPath

      Regards, Rashida Jabeen http://www.akaas.net[^]

      F 1 Reply Last reply
      0
      • I iamrashida83

        use using System.IO; // for C# Imports System.IO // for VB.NET and then try using Server.MapPath

        Regards, Rashida Jabeen http://www.akaas.net[^]

        F Offline
        F Offline
        Fred_Smith
        wrote on last edited by
        #3

        Thanks - but that doesn't work (which doesn't actually surprise me as "server" is not a member of system.io, as far as I can see...) In case it's not clear: I want to read a file from within a class module (as opposed to a code-behind module of a webapge) cheers F

        I 1 Reply Last reply
        0
        • F Fred_Smith

          Thanks - but that doesn't work (which doesn't actually surprise me as "server" is not a member of system.io, as far as I can see...) In case it's not clear: I want to read a file from within a class module (as opposed to a code-behind module of a webapge) cheers F

          I Offline
          I Offline
          iamrashida83
          wrote on last edited by
          #4

          its working fine at my side i m using it in a code class file (i.e. a data access class) not code behind file and it is working

          Regards, Rashida Jabeen http://www.akaas.net[^]

          F 1 Reply Last reply
          0
          • I iamrashida83

            its working fine at my side i m using it in a code class file (i.e. a data access class) not code behind file and it is working

            Regards, Rashida Jabeen http://www.akaas.net[^]

            F Offline
            F Offline
            Fred_Smith
            wrote on last edited by
            #5

            Well, I don't know. Thanks for ytour answer, but in my environment (VS2003) it simply doesn't recognise server.mappath within a class module.... remind me not to visit your akaas.net site again!! I lost count of the unwanted popups offering to install this that and the other... nothing turns me off a site faster than that! Didn't get past the first page but closed them all down as fast as I could.... cheers Fred

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups