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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Uploading file using Browse Btn & Downloading the attached file

Uploading file using Browse Btn & Downloading the attached file

Scheduled Pinned Locked Moved ASP.NET
question
3 Posts 3 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 Offline
    P Offline
    Program err
    wrote on last edited by
    #1

    How do i upload a file using browse button ? how do i then download the attached file (which was stored using Browse button !) ? Amol

    C S 2 Replies Last reply
    0
    • P Program err

      How do i upload a file using browse button ? how do i then download the attached file (which was stored using Browse button !) ? Amol

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Amol Palande wrote: How do i upload a file using browse button ? in the codebehind, fileControl has a property called FileBytes or something. Amol Palande wrote: how do i then download the attached file (which was stored using Browse button !) ? You can change the page header and write the file into it, or you can just provide a link to the file as you wrote it to the server. Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      • P Program err

        How do i upload a file using browse button ? how do i then download the attached file (which was stored using Browse button !) ? Amol

        S Offline
        S Offline
        Sketchy Steve
        wrote on last edited by
        #3

        Ere you go, This function take an image and an HtmlInputFile, it uploads the file, if it has the correct mime type - in the case an image type - it then appends the session state to the file name (to avoid overwriting any files of the same name) next it gets the physical uplication path and tells the function which sub dir to upload the file to. you want to use an tag on front end and refer to it as system.web.ui.htmlcontrols.htmlinputfile on back end. Hope this helps :) protected void UploadImage(ref Image imgUploadedImage, ref HtmlInputFile flInputImage) { if (flInputImage.PostedFile != null) { string PicType = flInputImage.PostedFile.ContentType.ToString(); if (PicType == "image/jpeg" || PicType == "image/gif" || PicType == "image/pjpeg" || PicType == "image/bmp") { try { string PicName = flInputImage.PostedFile.FileName; string NewPicName = (string)Session.SessionID + "_" + PicName.Substring(PicName.LastIndexOf(@"\")+1); string UploadPath = Request.PhysicalApplicationPath + @"\CMS\Uploads\"; flInputImage.PostedFile.SaveAs(UploadPath + NewPicName); imgUploadedImage.AlternateText = "Uploaded picture..."; imgUploadedImage.ImageUrl = "../CMS/Uploads/" + NewPicName; imgUploadedImage.Visible = true; } catch (Exception exc) { lblTest.CssClass = "Error"; lblTest.Text = exc.ToString(); } } else { lblTest.CssClass = "Error"; lblTest.Text = "File format not supported!"; } } }

        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