Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. File uploader

File uploader

Scheduled Pinned Locked Moved ASP.NET
helpquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Morgs Morgan
    wrote on last edited by
    #1

    Hey guys, am using a file uploader for a user to select a file, But only the files in my working directory are allowed. If I select a file outside my working directory i get an error saying: the path of the file could not be found...I would to choose a file from different directories Does any know what i can do on this one? Please help

    P V L 3 Replies Last reply
    0
    • M Morgs Morgan

      Hey guys, am using a file uploader for a user to select a file, But only the files in my working directory are allowed. If I select a file outside my working directory i get an error saying: the path of the file could not be found...I would to choose a file from different directories Does any know what i can do on this one? Please help

      P Offline
      P Offline
      Priya Prk
      wrote on last edited by
      #2

      Perhaps you don't have permission.

      1 Reply Last reply
      0
      • M Morgs Morgan

        Hey guys, am using a file uploader for a user to select a file, But only the files in my working directory are allowed. If I select a file outside my working directory i get an error saying: the path of the file could not be found...I would to choose a file from different directories Does any know what i can do on this one? Please help

        V Offline
        V Offline
        Viral Upadhyay
        wrote on last edited by
        #3

        You need to give more information of your code, then any one can look on it and tell you what is the problem. :)

        Viral My Site
        Save Our Tigers

        1 Reply Last reply
        0
        • M Morgs Morgan

          Hey guys, am using a file uploader for a user to select a file, But only the files in my working directory are allowed. If I select a file outside my working directory i get an error saying: the path of the file could not be found...I would to choose a file from different directories Does any know what i can do on this one? Please help

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Yes, we need detail description of your problem including code then only we can help you in better manner. :)

          Jinal Desai

          M 1 Reply Last reply
          0
          • L Lost User

            Yes, we need detail description of your problem including code then only we can help you in better manner. :)

            Jinal Desai

            M Offline
            M Offline
            Morgs Morgan
            wrote on last edited by
            #5

            Hey thanks guys for ya reps, well i wish i would xplain this better, Here is a piece of code: below 'files' is the name of my file uploader

            HttpPostedFile myFile = files.PostedFile;// Get a reference to PostedFile object
            string strFilename = Path.GetFileName(myFile.FileName);//path of a file
            if (strFilename != "")//check if a user has selected a file
            {
            string[] lines = File.ReadAllLines(strFilename);//will read all lines from a file
            //here a runtime error fires saying the file path was not found
            }

            Reason: As anyone one else knows, when you choose browse on a file uploader, you can only select a file if it is present in the dialog box that opens. So if I select a file in my working directory, it works ok but if i select a file 'Outside' my working directory then I receive the error above(file not found). E.g my working directory is: C:\MyProject\SMS Send\contacts.txt this works and if I choose: C:\Documents and Settings\Morgan\Desktop\testing.txt this will give a FileNotFound exception, and when i look at this exception it is pointing to:C:\MyProject\SMS Send\testing.txt which is my working directory. I don't quiet understand why it is searching for the file from my working directory.. Please help Thanks Mor

            W 1 Reply Last reply
            0
            • M Morgs Morgan

              Hey thanks guys for ya reps, well i wish i would xplain this better, Here is a piece of code: below 'files' is the name of my file uploader

              HttpPostedFile myFile = files.PostedFile;// Get a reference to PostedFile object
              string strFilename = Path.GetFileName(myFile.FileName);//path of a file
              if (strFilename != "")//check if a user has selected a file
              {
              string[] lines = File.ReadAllLines(strFilename);//will read all lines from a file
              //here a runtime error fires saying the file path was not found
              }

              Reason: As anyone one else knows, when you choose browse on a file uploader, you can only select a file if it is present in the dialog box that opens. So if I select a file in my working directory, it works ok but if i select a file 'Outside' my working directory then I receive the error above(file not found). E.g my working directory is: C:\MyProject\SMS Send\contacts.txt this works and if I choose: C:\Documents and Settings\Morgan\Desktop\testing.txt this will give a FileNotFound exception, and when i look at this exception it is pointing to:C:\MyProject\SMS Send\testing.txt which is my working directory. I don't quiet understand why it is searching for the file from my working directory.. Please help Thanks Mor

              W Offline
              W Offline
              www Developerof NET
              wrote on last edited by
              #6

              You need to user Server.MapPath() while retrieving the full path. e.g: string strFilename = Server.MapPath(Path.GetFileName(myFile.FileName));//path of a file I guess this should work now.

              When you fail to plan, you are planning to fail.

              M 1 Reply Last reply
              0
              • W www Developerof NET

                You need to user Server.MapPath() while retrieving the full path. e.g: string strFilename = Server.MapPath(Path.GetFileName(myFile.FileName));//path of a file I guess this should work now.

                When you fail to plan, you are planning to fail.

                M Offline
                M Offline
                Morgs Morgan
                wrote on last edited by
                #7

                Thanks for your reply man but hey this gives me the same error(FileNotFound Exception) I don't quiet know why... :doh:

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups