Results 1 to 6 of 6

Thread: HELP!!!!!! using Server.MapPath in a windows application?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    HELP!!!!!! using Server.MapPath in a windows application?

    I want to be able to use Server.MapPath in a windows application. I've added
    the system.web reference to my project but whenever I try to call it, I get
    a null reference error. Anyone can tell me how to use this function?
    (this is how I'm calling it:
    System.Web.HttpContext.Current.Server.MapPath() )
    Last edited by MrPolite; Mar 16th, 2004 at 02:15 PM.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    aah this sounds like a damn simple question and yet is taking me days to figure out someone help me please
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    This method returns the physical path of the website the code is operating in. It will not work from an outside application executing on the desktop or a remote computer as far as I know.

    VB Code:
    1. Dim myPhysicalPath As String = Server.MapPath("/MyWebSite")

    What are you trying to accomplish anyway... maybe i can help.

  4. #4

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by nemaroller
    This method returns the physical path of the website the code is operating in. It will not work from an outside application executing on the desktop or a remote computer as far as I know.

    VB Code:
    1. Dim myPhysicalPath As String = Server.MapPath("/MyWebSite")

    What are you trying to accomplish anyway... maybe i can help.
    hmmmm so it wont work with a win app?

    this was my problem:
    http://vbforums.com/showthread.php?threadid=282597


    I just want to be able to figure out the physical directory of something like this: http;//localhost/myAspProject

    I'm opening a vs.net solution file with streamreader, and in it, there is a asp.net project. The path of the asp.net project is written like above (the path starts with http://localhost rather than a drive letter... its not a physical path). Now I want to be able to open that asp.net project file with streamreader and I wont be able to do that unless I can convert the path.

    let me know if it's still not clear
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Ok...

    Well, you can't use Server.MapPath, that is useful for code operating within a website like say, I want to open a filestream inside server code to an image to my web's image folder... so i can manipulate it:

    VB Code:
    1. Dim myFilestream As New FileStream(Server.MapPath("/MyWebSite") & "/Images/" & filename, FileMode.Open, FileAccess.Read)


    What you want is the location of the website in the IIS server.. and that ultimately depends on a registry entry.

    Unfortunately, I don't know which one that would be.

    But, the ASP solution file itself usually resides in the MyDocuments/Visual Studio Projects folder... and then again, that can change depend on the IDE's configuration (registry again).

    As an additional (unhelpful for your problem) tip, you may want to substitute 127.0.0.1 for 'localhost' .

  6. #6

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by nemaroller
    Ok...

    Well, you can't use Server.MapPath, that is useful for code operating within a website like say, I want to open a filestream inside server code to an image to my web's image folder... so i can manipulate it:

    VB Code:
    1. Dim myFilestream As New FileStream(Server.MapPath("/MyWebSite") & "/Images/" & filename, FileMode.Open, FileAccess.Read)


    What you want is the location of the website in the IIS server.. and that ultimately depends on a registry entry.

    Unfortunately, I don't know which one that would be.

    But, the ASP solution file itself usually resides in the MyDocuments/Visual Studio Projects folder... and then again, that can change depend on the IDE's configuration (registry again).

    As an additional (unhelpful for your problem) tip, you may want to substitute 127.0.0.1 for 'localhost' .
    no streamreader says that it wont work with uri's at all...

    well someone did tell me a registry entry that has this value, but they too weren't sure if the iis' path will always be kept in this regkey, so thats why I was looking for an alternate way. (HKLM\System\CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots in the "\" key....)

    If as you say its not possible to use server.mappath then I guess I have to use the registry thingie hehe
    thanks for the replies
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width