locked
Reason of error RRS feed

  • Question

  • User364663285 posted

    Hi,

    C:\inetpub\vs2012\EditSelfIntro4


    is the path to which I've deployed the project.

    File output000.jpg, does exist within this path and what is the reason of error below?

    Could not find a part of the path '~/output000.jpg'.



    Sunday, August 16, 2020 3:32 PM

Answers

  • User753101303 posted

    Hi,

    Seems to happen with a file processing function? ~ is a special notation for the root of the web application which is never used "as is":

    • here it seems you want to use first Server.MapPath("~/output000.jpg") to convert that "virtual path" to a physical path such as "C:\inetpub\vs2012\EditSelfIntro4\output000.jpg"
    • else it is converted to a url such as "https://mysite.com/output000.jpg"

    It allows to write code without having to know where your site will be installed but it needs to be converted to a physical path or an url before being used.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 16, 2020 4:39 PM

All replies

  • User753101303 posted

    Hi,

    Seems to happen with a file processing function? ~ is a special notation for the root of the web application which is never used "as is":

    • here it seems you want to use first Server.MapPath("~/output000.jpg") to convert that "virtual path" to a physical path such as "C:\inetpub\vs2012\EditSelfIntro4\output000.jpg"
    • else it is converted to a url such as "https://mysite.com/output000.jpg"

    It allows to write code without having to know where your site will be installed but it needs to be converted to a physical path or an url before being used.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 16, 2020 4:39 PM
  • User364663285 posted

    How to resolve issue to ensure it would refer to file in path below?

    C:\inetpub\vs2012\EditSelfIntro4



    Monday, August 17, 2020 1:20 AM
  • User303363814 posted

    Do you want us to fix your code?  You will need to show your code!

    Monday, August 17, 2020 4:42 AM
  • User364663285 posted

    Here is the line 

                    File.Copy("~/output000.jpg", "~/output.jpg", true);
    

    leading to problem.

    Monday, August 17, 2020 6:35 AM
  • User303363814 posted

    PatriceSc has guessed that this was your code and shown the correct way to get the filename.

    Monday, August 17, 2020 7:10 AM
  • User753101303 posted

    So you try to copy a file found in a ~ folder. It should be for example :

      File.Copy(Server.MapPath("~/output000.jpg"), Server.MapPath("~/output.jpg"), true);
    Monday, August 17, 2020 12:03 PM