Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Server.MapPath() error 'ASP 0172 : 80004005'

Options
  • 16-08-2007 11:58am
    #1
    Registered Users Posts: 224 ✭✭


    :eek: Hi Im getting the following error, when trying to generate a mail. And below this is the code I have running. Anybody ideas what I should do here....:confused:


    Server.MapPath() error 'ASP 0172 : 80004005'

    Invalid Path

    /sqs/ie/chooseadd.asp, line 93

    The Path parameter for the MapPath method must be a virtual path. A physical path was used.

    ****************

    With rsCartDetails
    do until .eof
    If isnull(.Fields("ImageLink").value) Then
    objMail.AttachURL server.MapPath ("../siteimgs/noimage.jpg"), "noimage.jpg"
    Else
    set fso=CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(server.MapPath ( .Fields("ImageLink").value)) then
    objMail.AttachURL server.MapPath (.Fields("ImageLink").value), "noimage" & iImage & ".jpg"
    strImage="noimage" & iImage & ".jpg"
    iImage=iImage+1
    else
    objMail.AttachURL server.MapPath ("../siteimgs/noimage.jpg"), "noimage.jpg"
    end if
    End If

    ****************************


Comments

  • Registered Users Posts: 2,781 ✭✭✭amen


    basically you have told it to access a physical path such as c:\inetpub\wwwroot\myweb\image

    while it was looking for something like
    www.myweb.com\image

    google the error or go to
    msdn.microsoft.com


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    It's a really bad idea to keep re-using Server.MapPath as you are doing the in the code you posted especially as you are trying to access the same location each time. Server.[anything] is a request to use the servers resources, i.e. Server.MapPath uses up server clock time to work out where your location is and return the string representing your location. Each time you use it it uses up some resources and as this is a web page you could have multiple users requesting it simultaneously which will have a knock on effect to each one.

    As the other poster mentionned, google the error message and you should get a whole host of results on what is being done incorrectly and if you can try and change the code to remove the multiple server.mappath requests (if you have to use server.mappath then why not just call it once and store the value in a variable?)

    -RD


  • Registered Users Posts: 1,530 ✭✭✭CptSternn


    ron_darrell -

    He is only using mappath once - that is a conditional statement which is only using one mappath.

    Also, when dealing with HTML formatted email like in this example, it is the only way to attach graphics.

    Mighty Dubs -

    Here is your problem:

    objMail.AttachURL server.MapPath ("../siteimgs/noimage.jpg"), "noimage.jpg"

    It needs be be this:

    objMail.AttachURL server.MapPath ("C:\siteimgs\noimage.jpg"), "noimage.jpg"

    The MapPath FSO has to be pointed to an actual filename like you find in DOS.


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    CptSternn wrote:
    ron_darrell -

    He is only using mappath once - that is a conditional statement which is only using one mappath.

    Also, when dealing with HTML formatted email like in this example, it is the only way to attach graphics.

    That's just not true CptSternn. Server.MapPath just returns an absolute address (relative to the webserver machines root directory) for the file you are looking for. This is a string that can be stored in a variable.
    Dim empty_image , check_image
    empty_image = Server.MapPath("../siteimgs/noimage.jpg")
    
    With rsCartDetails
    do until .eof
    If isnull(.Fields("ImageLink").value) Then
    objMail.AttachURL empty_image, "noimage.jpg" 
    Else 
    set fso=CreateObject("Scripting.FileSystemObject") 
    check_image = server.MapPath (.Fields("ImageLink").value)
    If fso.FileExists(check_image) then
    objMail.AttachURL check_image, "noimage" & iImage & ".jpg" 
    strImage="noimage" & iImage & ".jpg"
    iImage=iImage+1
    else
    objMail.AttachURL empty_image, "noimage.jpg"
    end if
    End If
    

    Now just two server calls in the code.

    -RD


  • Registered Users Posts: 1,530 ✭✭✭CptSternn


    I hate to correct you, but your wrong mate.

    The user is trying to attach graphics to an email he is sending via CDO on a Windows2000 server/IIS6. You can tell that from the code. In Server 2003 and Server 2007, they have implemented a new way of sending mail, and the CDO code above does not work, so we can safely assume that is the OS and since I have written that exact code many, many times I can tell you that you have to have the mapped address as listed above.

    Here are some links to examples...

    http://www.w3schools.com/asp/asp_send_email.asp

    http://www.chrishardy.co.uk/asp/tutorials/email-cdonts.asp

    Both include similar code with the same purpose.

    -S


  • Advertisement
  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    And I hate to correct you 'mate' but server.mappath returns a string giving the absolute address of the relative path you provide. The code I provided does this in a much more efficient way removing the need for multiple calls to the server to return the same data. Maybe you have written the same code many times, there are more than singular ways of achieving the same goal. Some are more efficient than others.

    But are we not getting side-tracked. Original poster, have you been helped in any way?

    -RD


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    CptSternn - have you even been reading the responses in this thread? ron_darrell isn't discussing sending an email via CDO or any other method - he's discussing the OP's Server.MapPath() issue. And has provided a correct and relevent answer unlike you.
    The MapPath FSO has to be pointed to an actual filename like you find in DOS.

    To repeat ron_darrell: MapPath maps a virtual directory to a physical one which is the opposite of what you said.

    Looky here: http://msdn2.microsoft.com/en-us/library/ms524632.aspx.

    For the OP - when I get an error I don't understand I generally google it. In your case I would have googled Server.MapPath() error 'ASP 0172 : 80004005' Invalid Path. It generally gives you somewhere to start.


  • Registered Users Posts: 1,530 ✭✭✭CptSternn


    The example which the poster is having problems with is attempting to attach a URL to a CDO email on a Windows2000 server. There is only one way to do it. I provided links to two separate examples that are almost identical to the posters original code, with the small exception of the mappath statements, which as if you bothered to check the examples, are the same as in the example I provided above.


  • Registered Users Posts: 224 ✭✭The Mighty Dubs


    And I hate to correct you 'mate' but server.mappath returns a string giving the absolute address of the relative path you provide. The code I provided does this in a much more efficient way removing the need for multiple calls to the server to return the same data. Maybe you have written the same code many times, there are more than singular ways of achieving the same goal. Some are more efficient than others.

    But are we not getting side-tracked. Original poster, have you been helped in any way?

    -RD


    Hi guys,
    Thanks for all the feedback on this. As i may of mentioned before I farely new to all this and I appreciate the reponses guys. Im still scratching my head a little (not unusual practice for me).

    I tried using the "DOS" method as you suggested and returned the following error

    **********************************

    Server.MapPath() error 'ASP 0172 : 80004005'

    Invalid Path

    /sqs/ie/chooseadd.asp, line 91

    The Path parameter for the MapPath method must be a virtual path. A physical path was used.

    *******************************************
    This is the code i used


    With rsCartDetails
    do until .eof
    If isnull(.Fields("ImageLink").value) Then
    objMail.AttachURL server.MapPath ("C:/inetpub/wwwroot/xyz/siteimgs/noimage.jpg"), "noimage.jpg"
    Else
    set fso=CreateObject("Scripting.FileSystemObject")
    If fso.FileExists(server.MapPath ("" & .Fields("ImageLink").value)) then
    objMail.AttachURL server.MapPath ("" & .Fields("imageLink").value), "noimage" & iImage & ".jpg"
    strImage="noimage" & iImage & ".jpg"
    iImage=iImage+1
    else
    objMail.AttachURL server.MapPath ("C:/inetpub/wwwroot/xyz/siteimgs/noimage.jpg"), "noimage.jpg"
    end if
    End If

    *************************************************


  • Registered Users Posts: 1,530 ✭✭✭CptSternn


    Switch your back-slashes with forward slashes.


  • Advertisement
  • Registered Users Posts: 224 ✭✭The Mighty Dubs


    Hi,

    Tried that but received this error...any ideas


    Server.MapPath() error 'ASP 0172 : 80004005'

    Invalid Path

    /sqs/ie/chooseadd.asp, line 91

    The Path parameter for the MapPath method must be a virtual path. A physical path was used.


  • Registered Users Posts: 1,530 ✭✭✭CptSternn


    I take it your trying to send an email via CDO on a W2K box?

    First, what are you editing in? Virtual Studio? Dreamweaver?

    Can you find the line number in your example which matches the error?

    My guess is one of the variables your mapping is not coming through, making the path invalid (i.e. FIELD or VALUE).


Advertisement