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 and download file

upload and download file

Scheduled Pinned Locked Moved ASP.NET
sysadmintutorial
6 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.
  • N Offline
    N Offline
    niki_nilu
    wrote on last edited by
    #1

    hi i want upload file on server. and how to download it. gayatri

    Gayatri

    N 1 Reply Last reply
    0
    • N niki_nilu

      hi i want upload file on server. and how to download it. gayatri

      Gayatri

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      niki_nilu wrote:

      i want upload file on server.

      Use FileUpload control.

      niki_nilu wrote:

      and how to download it.

      Just redirect to that file. Response.Redirect("FileName.extension");

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

      N 1 Reply Last reply
      0
      • N N a v a n e e t h

        niki_nilu wrote:

        i want upload file on server.

        Use FileUpload control.

        niki_nilu wrote:

        and how to download it.

        Just redirect to that file. Response.Redirect("FileName.extension");

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

        N Offline
        N Offline
        niki_nilu
        wrote on last edited by
        #3

        hi yes i took input file control. but where i will see that uploaded file. my code is--

        if (File1.PostedFile != null) //Checking for valid file
        {
        // Since the PostedFile.FileNameFileName gives the entire path we use Substring function to rip of the filename alone.
        string StrFileName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") + 1);
        string StrFileType = File1.PostedFile.ContentType;
        int IntFileSize = File1.PostedFile.ContentLength;
        //Checking for the length of the file. If length is 0 then file is not uploaded.
        if (IntFileSize <= 0)
        Response.Write("<font color='Red' size='2'>Uploading of file " + StrFileName + " failed </font>");
        else
        {
        File1.PostedFile.SaveAs(Server.MapPath(".\\" + StrFileName));
        Messagebox.Show("Your file was uploaded successfully");
        //Response.Write("<font color='green' size='2'>Your file " + StrFileName + " of type " + StrFileType + " and size " + IntFileSize.ToString() + " bytes was uploaded successfully</font>");
        }
        }

        Gayatri

        A M N 3 Replies Last reply
        0
        • N niki_nilu

          hi yes i took input file control. but where i will see that uploaded file. my code is--

          if (File1.PostedFile != null) //Checking for valid file
          {
          // Since the PostedFile.FileNameFileName gives the entire path we use Substring function to rip of the filename alone.
          string StrFileName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") + 1);
          string StrFileType = File1.PostedFile.ContentType;
          int IntFileSize = File1.PostedFile.ContentLength;
          //Checking for the length of the file. If length is 0 then file is not uploaded.
          if (IntFileSize <= 0)
          Response.Write("<font color='Red' size='2'>Uploading of file " + StrFileName + " failed </font>");
          else
          {
          File1.PostedFile.SaveAs(Server.MapPath(".\\" + StrFileName));
          Messagebox.Show("Your file was uploaded successfully");
          //Response.Write("<font color='green' size='2'>Your file " + StrFileName + " of type " + StrFileType + " and size " + IntFileSize.ToString() + " bytes was uploaded successfully</font>");
          }
          }

          Gayatri

          A Offline
          A Offline
          AhsanS
          wrote on last edited by
          #4

          When you are using some one else code. Please try to understand it first. File1.PostedFile.SaveAs(Server.MapPath(".\\" + StrFileName)); You are giving this path. So it will be uploaded there.

          Ahsan Ullah Senior Software Engineer

          1 Reply Last reply
          0
          • N niki_nilu

            hi yes i took input file control. but where i will see that uploaded file. my code is--

            if (File1.PostedFile != null) //Checking for valid file
            {
            // Since the PostedFile.FileNameFileName gives the entire path we use Substring function to rip of the filename alone.
            string StrFileName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") + 1);
            string StrFileType = File1.PostedFile.ContentType;
            int IntFileSize = File1.PostedFile.ContentLength;
            //Checking for the length of the file. If length is 0 then file is not uploaded.
            if (IntFileSize <= 0)
            Response.Write("<font color='Red' size='2'>Uploading of file " + StrFileName + " failed </font>");
            else
            {
            File1.PostedFile.SaveAs(Server.MapPath(".\\" + StrFileName));
            Messagebox.Show("Your file was uploaded successfully");
            //Response.Write("<font color='green' size='2'>Your file " + StrFileName + " of type " + StrFileType + " and size " + IntFileSize.ToString() + " bytes was uploaded successfully</font>");
            }
            }

            Gayatri

            M Offline
            M Offline
            Manas Bhardwaj
            wrote on last edited by
            #5

            niki_nilu wrote:

            but where i will see that uploaded file.

            In the virtual directory of your web. :-O

            Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

            1 Reply Last reply
            0
            • N niki_nilu

              hi yes i took input file control. but where i will see that uploaded file. my code is--

              if (File1.PostedFile != null) //Checking for valid file
              {
              // Since the PostedFile.FileNameFileName gives the entire path we use Substring function to rip of the filename alone.
              string StrFileName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") + 1);
              string StrFileType = File1.PostedFile.ContentType;
              int IntFileSize = File1.PostedFile.ContentLength;
              //Checking for the length of the file. If length is 0 then file is not uploaded.
              if (IntFileSize <= 0)
              Response.Write("<font color='Red' size='2'>Uploading of file " + StrFileName + " failed </font>");
              else
              {
              File1.PostedFile.SaveAs(Server.MapPath(".\\" + StrFileName));
              Messagebox.Show("Your file was uploaded successfully");
              //Response.Write("<font color='green' size='2'>Your file " + StrFileName + " of type " + StrFileType + " and size " + IntFileSize.ToString() + " bytes was uploaded successfully</font>");
              }
              }

              Gayatri

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #6

              niki_nilu wrote:

              if (File1.PostedFile != null)

              If you are using ASp.NET file upload control use File1.HasFile

              niki_nilu wrote:

              string StrFileName = File1.PostedFile.FileName.Substring(File1.PostedFile.FileName.LastIndexOf("\\") + 1);

              string StrFileName = IO.Path.GetFileName(File1.PostedFile.FileName);

              niki_nilu wrote:

              but where i will see that uploaded file.

              In the same place where you are uploading it :confused:

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

              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