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. Fileupload problem, please help.

Fileupload problem, please help.

Scheduled Pinned Locked Moved ASP.NET
databasehelpsysadmin
8 Posts 4 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.
  • F Offline
    F Offline
    Farraj
    wrote on last edited by
    #1

    Hi, I have a database (access) that contains a table GALLERY. Now i need while uploading a file to insert the path in this way to the db "~/photo/XXX.JPG" What i get right now is only the file's name. This is what i used for saving the path FileUpload1.SaveAs(Server.MapPath("~/photo/" + FileUpload1.FileName)); I've tried it with and without the Server.MapPath. The resault without the server.mappath was "The SaveAs method is configured to require a rooted path..bla bla bla" With the Server.MapPath it works but not the way i need it. as i said it inserts only the file's name to the DB. Can anyone please help me with that. Thank you, Basil.

    S N F 3 Replies Last reply
    0
    • F Farraj

      Hi, I have a database (access) that contains a table GALLERY. Now i need while uploading a file to insert the path in this way to the db "~/photo/XXX.JPG" What i get right now is only the file's name. This is what i used for saving the path FileUpload1.SaveAs(Server.MapPath("~/photo/" + FileUpload1.FileName)); I've tried it with and without the Server.MapPath. The resault without the server.mappath was "The SaveAs method is configured to require a rooted path..bla bla bla" With the Server.MapPath it works but not the way i need it. as i said it inserts only the file's name to the DB. Can anyone please help me with that. Thank you, Basil.

      S Offline
      S Offline
      Sandeep Mewara
      wrote on last edited by
      #2

      The FileUpload control has a SaveAs(string path) method. You can use that method to save the file to any path using any filename you want. Just make sure ASP.NET has permissions to write to that path. So, you can do something like this to save the uploaded file to the uploads folder in the root of your website:

      fileUpload1.SaveAs(Server.MapPath(“~/uploads/”)

      • System.IO.Path.GetFilename(fileUpload1.FileName));
      F 1 Reply Last reply
      0
      • S Sandeep Mewara

        The FileUpload control has a SaveAs(string path) method. You can use that method to save the file to any path using any filename you want. Just make sure ASP.NET has permissions to write to that path. So, you can do something like this to save the uploaded file to the uploads folder in the root of your website:

        fileUpload1.SaveAs(Server.MapPath(“~/uploads/”)

        • System.IO.Path.GetFilename(fileUpload1.FileName));
        F Offline
        F Offline
        Farraj
        wrote on last edited by
        #3

        thank u for ur reply i've tried that, still at my database i get only the file's name without the path ~/folder/... i need to add it as a string before the file's name. or! if there was a way for inserting like an auto text option to that column each time i insert the data (before the file name). any idea how? thanks

        1 Reply Last reply
        0
        • F Farraj

          Hi, I have a database (access) that contains a table GALLERY. Now i need while uploading a file to insert the path in this way to the db "~/photo/XXX.JPG" What i get right now is only the file's name. This is what i used for saving the path FileUpload1.SaveAs(Server.MapPath("~/photo/" + FileUpload1.FileName)); I've tried it with and without the Server.MapPath. The resault without the server.mappath was "The SaveAs method is configured to require a rooted path..bla bla bla" With the Server.MapPath it works but not the way i need it. as i said it inserts only the file's name to the DB. Can anyone please help me with that. Thank you, Basil.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          Do not post to multiple forum :mad:


          I know the language. I've read a book. - _Madmatt

          1 Reply Last reply
          0
          • F Farraj

            Hi, I have a database (access) that contains a table GALLERY. Now i need while uploading a file to insert the path in this way to the db "~/photo/XXX.JPG" What i get right now is only the file's name. This is what i used for saving the path FileUpload1.SaveAs(Server.MapPath("~/photo/" + FileUpload1.FileName)); I've tried it with and without the Server.MapPath. The resault without the server.mappath was "The SaveAs method is configured to require a rooted path..bla bla bla" With the Server.MapPath it works but not the way i need it. as i said it inserts only the file's name to the DB. Can anyone please help me with that. Thank you, Basil.

            F Offline
            F Offline
            Farraj
            wrote on last edited by
            #5

            im sorry actually i disabled the code lol now im running this code ugave me and im getting some errors. System.IO.Path' does not contain a definition for 'GetFilename' The name 'fileUpload1' does not exist in the current context

            M 1 Reply Last reply
            0
            • F Farraj

              im sorry actually i disabled the code lol now im running this code ugave me and im getting some errors. System.IO.Path' does not contain a definition for 'GetFilename' The name 'fileUpload1' does not exist in the current context

              M Offline
              M Offline
              michaelschmitt
              wrote on last edited by
              #6

              Hi there, the ID of your upload Control is "FileUpload1" in your example, not "fileUpload1". Always pay attention to the letter case. Same with GetFilename. The Method is written "GetFileName". What the upload control does, is the following: it saves your selected file to the file-system. No path-saving to your database at this point. Where are you saving the path to your db? there you have to save the virtual path of your upload folder in addition to your filename. Just concat the strings there. Good Luck

              F 1 Reply Last reply
              0
              • M michaelschmitt

                Hi there, the ID of your upload Control is "FileUpload1" in your example, not "fileUpload1". Always pay attention to the letter case. Same with GetFilename. The Method is written "GetFileName". What the upload control does, is the following: it saves your selected file to the file-system. No path-saving to your database at this point. Where are you saving the path to your db? there you have to save the virtual path of your upload folder in addition to your filename. Just concat the strings there. Good Luck

                F Offline
                F Offline
                Farraj
                wrote on last edited by
                #7

                Hi michaelschmitt, thank you for ur reply and for ur information :) the letters are actualy as they should be. ____ I still cannot get it fixed even after adding the System.IO.Path.. // FileUpload1.PostedFile.SaveAs(Server.MapPath(("~/photo/" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)))); //

                M 1 Reply Last reply
                0
                • F Farraj

                  Hi michaelschmitt, thank you for ur reply and for ur information :) the letters are actualy as they should be. ____ I still cannot get it fixed even after adding the System.IO.Path.. // FileUpload1.PostedFile.SaveAs(Server.MapPath(("~/photo/" + System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)))); //

                  M Offline
                  M Offline
                  michaelschmitt
                  wrote on last edited by
                  #8

                  What i was trying to say is that your posted code does not include any interaction with your access database. It just takes the selected filename from your upload control and saves this file to the desired folder. This code alone would not insert the filename into your access-database table. To clarify: "~/photo/" is the virtual path of your upload folder. Server.MapPath is needed to tranform this to the corresponding physical directory on your web-server (e.g.: c:\http\mysite\photo). FileUpload1.SaveAs(...) saves your file to this folder. Use string virtualFilePath = "~/photo/" + FileUpload1.FileName; to get your desired Path und save it to your database.

                  modified on Monday, March 29, 2010 9:43 AM

                  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