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. Problem with filepath while reading to filestream

Problem with filepath while reading to filestream

Scheduled Pinned Locked Moved ASP.NET
helpsysadmin
11 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.
  • A anujose

    i have the path of a file in a string variable. i am reading that using the following code new FileStream(path, FileMode.Open, FileAccess.Read); it's working fine when i execute from local machine .when i upload it into server it is showing the error 'Could not find a part of the file.. Any one can help me......... Anu

    I Offline
    I Offline
    Imran Khan Pathan
    wrote on last edited by
    #2

    try this code new FileStream(Server.MapPath(path), FileMode.Open, FileAccess.Read); Best Regard Pathan

    ---------------------------------------------------

    A 1 Reply Last reply
    0
    • I Imran Khan Pathan

      try this code new FileStream(Server.MapPath(path), FileMode.Open, FileAccess.Read); Best Regard Pathan

      ---------------------------------------------------

      A Offline
      A Offline
      anujose
      wrote on last edited by
      #3

      Then it'is coming like this 'D:\Anu\Pic1.bmp' is not a valid virtual path.

      G 1 Reply Last reply
      0
      • A anujose

        Then it'is coming like this 'D:\Anu\Pic1.bmp' is not a valid virtual path.

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #4

        You can't read a file that doesn't exist. Put the file that you want to read on the server. Put the virtual path to the file in the path variable, and use Server.MapPath(path) to get the physical path to the file.

        --- single minded; short sighted; long gone;

        A 1 Reply Last reply
        0
        • G Guffa

          You can't read a file that doesn't exist. Put the file that you want to read on the server. Put the virtual path to the file in the path variable, and use Server.MapPath(path) to get the physical path to the file.

          --- single minded; short sighted; long gone;

          A Offline
          A Offline
          anujose
          wrote on last edited by
          #5

          i didn't understand.can you give me a sample code?..

          A G 2 Replies Last reply
          0
          • A anujose

            i didn't understand.can you give me a sample code?..

            A Offline
            A Offline
            anujose
            wrote on last edited by
            #6

            How can i put the file into the server using path. if i am using file upload control then i can use fileuploadcontrolname.postedfile.saveas(server.mapath(filename)).but i am not using that control.i am only have the path of the file in a string variable...How can i do....... Anu

            S 1 Reply Last reply
            0
            • A anujose

              i have the path of a file in a string variable. i am reading that using the following code new FileStream(path, FileMode.Open, FileAccess.Read); it's working fine when i execute from local machine .when i upload it into server it is showing the error 'Could not find a part of the file.. Any one can help me......... Anu

              B Offline
              B Offline
              Blue_Boy
              wrote on last edited by
              #7

              Guffa was right and I just submit his answer with simple code //fudoc is HtmlInuptFile //UplDoc is Folder inside project FileInfo fInfo = new FileInfo(fudoc.Value.ToString());//here get path of local machine fudoc.PostedFile.SaveAs(Server.MapPath("~/UplDoc/") + fInfo.Name);//here save file in folder which exists in project after this read file from Folder UplDoc FileInfo fi = new FileInfo(Server.MapPath("~/UplDoc/filename.extension")); Hope it helped


              I Love SQL

              S 1 Reply Last reply
              0
              • A anujose

                How can i put the file into the server using path. if i am using file upload control then i can use fileuploadcontrolname.postedfile.saveas(server.mapath(filename)).but i am not using that control.i am only have the path of the file in a string variable...How can i do....... Anu

                S Offline
                S Offline
                Sandeep Akhare
                wrote on last edited by
                #8

                You can't do that directly SO you want to read the Uploaded file then use fileuploadID.PostedFile.InputStream as input to Stream reader and read the file

                Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                1 Reply Last reply
                0
                • B Blue_Boy

                  Guffa was right and I just submit his answer with simple code //fudoc is HtmlInuptFile //UplDoc is Folder inside project FileInfo fInfo = new FileInfo(fudoc.Value.ToString());//here get path of local machine fudoc.PostedFile.SaveAs(Server.MapPath("~/UplDoc/") + fInfo.Name);//here save file in folder which exists in project after this read file from Folder UplDoc FileInfo fi = new FileInfo(Server.MapPath("~/UplDoc/filename.extension")); Hope it helped


                  I Love SQL

                  S Offline
                  S Offline
                  Sandeep Akhare
                  wrote on last edited by
                  #9

                  i think no need to save also give one of the steamreader parameter as uploadfileCntrolID.Postedfile.InputStream

                  Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                  B 1 Reply Last reply
                  0
                  • S Sandeep Akhare

                    i think no need to save also give one of the steamreader parameter as uploadfileCntrolID.Postedfile.InputStream

                    Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "

                    B Offline
                    B Offline
                    Blue_Boy
                    wrote on last edited by
                    #10

                    It was my quick answer Addition in my previous post: After the job is done with file then file can be deleted FileInfo fdelete = new FileInfo(Server.MapPath("~/UplDoc/filename.extension")); fdelete.Delete();


                    I Love SQL

                    1 Reply Last reply
                    0
                    • A anujose

                      i didn't understand.can you give me a sample code?..

                      G Offline
                      G Offline
                      Guffa
                      wrote on last edited by
                      #11

                      anujose wrote:

                      i didn't understand.can you give me a sample code?..

                      The example code will be exactly as Pathan showed: new FileStream(Server.MapPath(path), FileMode.Open, FileAccess.Read); The path in the path variable should be a virtual path, like for example "/SomeFolder/SomeFile.txt".

                      --- single minded; short sighted; long gone;

                      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