convert from physical path to virtual path

后端 未结 3 1030
野性不改
野性不改 2020-12-15 21:36

I have this function that gets the fileData as a byte array and a file path. The error I am getting is when it tries to set the fileInfo in the code bewlo. It says \'Physica

相关标签:
3条回答
  • 2020-12-15 21:41

    I take it that your project is located at:

    E:\WEBS\\webapp\
    

    You should try and use relative references to your images e.g.

    ..\default\images\mains\myimage.jpg
    
    0 讨论(0)
  • 2020-12-15 21:42

    Working:

        string[] filesPath = Directory.GetFiles(Server.MapPath("~/txtPath/"));        
        foreach (string path in filesPath)
        {
            FileInfo fi = new FileInfo(path);      //This Is Working
           string LastAcceTime = fi.LastWriteTime; //Return Correct Value
        }
    

    Not Working:

        string[] filesPath = Directory.GetFiles(Server.MapPath("~/txtPath/"));        
        foreach (string path in filesPath)
        {
            FileInfo fi = new FileInfo(Server.MapPath(path));  //This Is Worng
           string LastAcceTime = fi.LastWriteTime;             //Return 1/1/1601 
        }
    

    Dont use Server.Mappath twice

    0 讨论(0)
  • 2020-12-15 21:58

    If you already have a physical path, it doesn't make sense to call Server.MapPath.

    You're calling MapPath twice.

    0 讨论(0)
提交回复
热议问题