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. Upload file to server

Upload file to server

Scheduled Pinned Locked Moved ASP.NET
helpsysadmin
14 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.
  • P priyagee

    Hai all, I need to upload file to server and i am using input file to upload the file, my problem is postedfile.filename is always null. I have tried using updatepanel and had same problem. Can anyone help me.

    H Offline
    H Offline
    Hiren solanki
    wrote on last edited by
    #2

    File upload doesn't work under UpdatePanel ByDefault. you need to set PostBackTrigger in <Triggers> Section of UpdatePanel by which you can force a complete PostBack.

    Regards, Hiren. "The more we give of anything, the more we shall get back." - Grace Speare (you can consider this quote while giving vote also) Microsoft Dynamics CRM

    P 1 Reply Last reply
    0
    • H Hiren solanki

      File upload doesn't work under UpdatePanel ByDefault. you need to set PostBackTrigger in <Triggers> Section of UpdatePanel by which you can force a complete PostBack.

      Regards, Hiren. "The more we give of anything, the more we shall get back." - Grace Speare (you can consider this quote while giving vote also) Microsoft Dynamics CRM

      P Offline
      P Offline
      priyagee
      wrote on last edited by
      #3

      I have tried that too but still it didnt work , the postedfile is null.

      H 1 Reply Last reply
      0
      • P priyagee

        I have tried that too but still it didnt work , the postedfile is null.

        H Offline
        H Offline
        Hiren solanki
        wrote on last edited by
        #4

        Make sure you are using it under !Page.IsPostBack Condition.

        Regards, Hiren. "The more we give of anything, the more we shall get back." - Grace Speare (you can consider this quote while giving vote also) Microsoft Dynamics CRM

        P 1 Reply Last reply
        0
        • H Hiren solanki

          Make sure you are using it under !Page.IsPostBack Condition.

          Regards, Hiren. "The more we give of anything, the more we shall get back." - Grace Speare (you can consider this quote while giving vote also) Microsoft Dynamics CRM

          P Offline
          P Offline
          priyagee
          wrote on last edited by
          #5

          Actually in my form i had a ultrawebgrid and a template column as button, when click the button by client side the value ll be assign to the fileupload control and when i click the upload button the file should be uploaded . My ultrawebgrid and upload button is inside refresh panel and fileupload is outside the refreshpanel.

          T 1 Reply Last reply
          0
          • P priyagee

            Actually in my form i had a ultrawebgrid and a template column as button, when click the button by client side the value ll be assign to the fileupload control and when i click the upload button the file should be uploaded . My ultrawebgrid and upload button is inside refresh panel and fileupload is outside the refreshpanel.

            T Offline
            T Offline
            T M Gray
            wrote on last edited by
            #6

            You can't assign the filename in an upload control with javascript. That is a security feature. Otherwise a web site could tell the browser to upload things like password files and steal data.

            H 1 Reply Last reply
            0
            • P priyagee

              Hai all, I need to upload file to server and i am using input file to upload the file, my problem is postedfile.filename is always null. I have tried using updatepanel and had same problem. Can anyone help me.

              P Offline
              P Offline
              PunkIsNotDead
              wrote on last edited by
              #7

              Hi! I recomend you to use Uploadify control of jQuery! Is the easy and best upload control! for multiple or single, max capacity, type of files, queue files in progress, multi browser, etc! Here[^] :)

              1 Reply Last reply
              0
              • T T M Gray

                You can't assign the filename in an upload control with javascript. That is a security feature. Otherwise a web site could tell the browser to upload things like password files and steal data.

                H Offline
                H Offline
                Hiren solanki
                wrote on last edited by
                #8

                T M Gray wrote:

                You can't assign the filename in an upload control with javascript

                He's probably not asking of assigning values rather He wants value inside.

                Regards, Hiren. "The more we give of anything, the more we shall get back." - Grace Speare (you can consider this quote while giving vote also) Microsoft Dynamics CRM

                P 1 Reply Last reply
                0
                • H Hiren solanki

                  T M Gray wrote:

                  You can't assign the filename in an upload control with javascript

                  He's probably not asking of assigning values rather He wants value inside.

                  Regards, Hiren. "The more we give of anything, the more we shall get back." - Grace Speare (you can consider this quote while giving vote also) Microsoft Dynamics CRM

                  P Offline
                  P Offline
                  priyagee
                  wrote on last edited by
                  #9

                  Yes i need only the value , in client side i am getting the path value but in server side it is null.

                  M 1 Reply Last reply
                  0
                  • P priyagee

                    Yes i need only the value , in client side i am getting the path value but in server side it is null.

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

                    string fn = Path.GetFileName(inputFile.PostedFile.FileName);
                    string savepath = Server.MapPath("Exports") + "\\" + fn;//Exports is a folder where u will save all the posted files...
                    inputFile.PostedFile.SaveAs(savepath);//makes a copy of the file onto your server...
                    string[] lines = File.ReadAllLines(savepath);//will read all lines from a file

                    for (int i = 0; i < lines.Length; i++)//loop through all the lines in your file
                    {
                    //do everything you want with the file contents
                    }

                    ; Hope that helps.. Later!

                    P 1 Reply Last reply
                    0
                    • M Morgs Morgan

                      string fn = Path.GetFileName(inputFile.PostedFile.FileName);
                      string savepath = Server.MapPath("Exports") + "\\" + fn;//Exports is a folder where u will save all the posted files...
                      inputFile.PostedFile.SaveAs(savepath);//makes a copy of the file onto your server...
                      string[] lines = File.ReadAllLines(savepath);//will read all lines from a file

                      for (int i = 0; i < lines.Length; i++)//loop through all the lines in your file
                      {
                      //do everything you want with the file contents
                      }

                      ; Hope that helps.. Later!

                      P Offline
                      P Offline
                      priyagee
                      wrote on last edited by
                      #11

                      Thnak u for the reply , I ll try it.

                      M 1 Reply Last reply
                      0
                      • P priyagee

                        Thnak u for the reply , I ll try it.

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

                        It works, if u need more help hala at me...

                        P 1 Reply Last reply
                        0
                        • M Morgs Morgan

                          It works, if u need more help hala at me...

                          P Offline
                          P Offline
                          priyagee
                          wrote on last edited by
                          #13

                          I have tried it but still i am getting null. PostedFile.FileName is null.

                          M 1 Reply Last reply
                          0
                          • P priyagee

                            I have tried it but still i am getting null. PostedFile.FileName is null.

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

                            You might want to take a look at what exactly you are doing in your Page_Load event...you could be reseting the values of your controls... Put the code above in a method e.g.:

                            protected void Page_Load(object sender, EventArgs e)
                            {
                            if(!IsPostBack)
                            {
                            UploadFile();//call your method here...
                            }//or put this ispostback check in the click event of the control/button that will do the uploading process
                            }

                            protected void UploadFile()
                            {
                            //put the code i gave you here...
                            }

                            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