Why the System.IO.File.Exists(fullpath) fails ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sudhaMurugesan
    New Member
    • May 2007
    • 94

    Why the System.IO.File.Exists(fullpath) fails ?

    Hi all,
    I use asp.net with c#. I upload a file and save in a directory. I want to reopen the file so i check for file exists and then open it. But though the file exists, the file.exists(ful lpath) returns false . can anyone help me ? My code is here...
    [CODE=C#]
    string paths = this.MapPath(". ./TerminateDoc/Excel/" + fileName.Trim() );
    /* paths = C:\\Inetpub\\ww wroot\\EIS\\Emp loyee.Web\\Term inateDoc\\Excel \\fi0002264Proo fDoc20080708101 851.txt */
    if (File.Exists(pa ths)) // returns false ????
    {
    FileInfo fi = new FileInfo(paths) ;
    Response.Clear( );
    Response.ClearH eaders();
    Response.Buffer = false;

    Response.Append Header("Content-Disposition", "attachment;fil ename=" + System.Web.Http Utility.UrlEnco de(System.Text. Encoding.UTF8.G etBytes(fileNam e)));// + System.Web.Http Utility.UrlEnco de(System.Text. Encoding.UTF8.G etBytes(Path.Ge tFileName(paths ))));
    Response.Append Header("Content-Length", fi.Length.ToStr ing());
    Response.Conten tType = "applicatio n/octet-stream";
    Response.WriteF ile(paths);
    Response.Flush( );
    Response.End();
    }
    else
    {
    this.RegisterSt artupScript("er ror", "<script>alert( 'The file is not uploaded or it has been deleted!');</script>");
    }[/CODE]

    Thank You
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Does it return false even if you use
    Code:
    paths = C:\\Inetpub\\wwwroot\\EIS\\Employee.Web\\TerminateDoc\\Excel\\fi0002264ProofDoc20080708101851.txt;
    for the path?

    Comment

    • sudhaMurugesan
      New Member
      • May 2007
      • 94

      #3
      Originally posted by r035198x
      Does it return false even if you use
      Code:
      paths = C:\\Inetpub\\wwwroot\\EIS\\Employee.Web\\TerminateDoc\\Excel\\fi0002264ProofDoc20080708101851.txt;
      for the path?
      Sorry for late reply..
      Thanks for ur reply. If i give the full path it works fine. But i cannot give the full path because while deploying it in the server, the root directory will differ.

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        Could you use Server.MapPath( filename) to get the full path?

        Dr B

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Are you sure you have access to those paths/files?
          .Exists() will fail on denied access as well as not existing I think.

          Comment

          • sudhaMurugesan
            New Member
            • May 2007
            • 94

            #6
            Originally posted by Plater
            Are you sure you have access to those paths/files?
            .Exists() will fail on denied access as well as not existing I think.
            I have access to that path.Thats why when i give the full path it can find the file. But still it fails.
            Also Server.Mappath fails. I cannot trace out the reason. Please Help me!

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              I am thinking that it is a simple copy/paste type mistake. Like one of your strings doesn't contain the extension of the filename or something like that.
              Have you set breakpoints and stepped through?
              Maybe do a GetFiles() on the directory and manually verify that your filename is in there?

              Comment

              • sudhaMurugesan
                New Member
                • May 2007
                • 94

                #8
                Originally posted by Plater
                I am thinking that it is a simple copy/paste type mistake. Like one of your strings doesn't contain the extension of the filename or something like that.
                Have you set breakpoints and stepped through?
                Maybe do a GetFiles() on the directory and manually verify that your filename is in there?
                Hi Plater,
                Yes i missed out the extension. Sorry to trouble u much. Thanks a lot.

                Comment

                Working...