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. file upload in asp.net 1.1

file upload in asp.net 1.1

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminquestion
4 Posts 2 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
    Pradip Kishore
    wrote on last edited by
    #1

    hi i want to upload a file(.doc,.jpg etc..) into a web server by clicking on the browse button and selecting the file path from the local machine i have to upload the file. how can i do this (also how can i have the browse button ..so that when i will click over it it will open a dialouge box for file selection as usually in job sites where the user have to upload their cvs)i am using vb.net as code behind thanks in advance

    pradip kishore

    N 1 Reply Last reply
    0
    • P Pradip Kishore

      hi i want to upload a file(.doc,.jpg etc..) into a web server by clicking on the browse button and selecting the file path from the local machine i have to upload the file. how can i do this (also how can i have the browse button ..so that when i will click over it it will open a dialouge box for file selection as usually in job sites where the user have to upload their cvs)i am using vb.net as code behind thanks in advance

      pradip kishore

      N Offline
      N Offline
      NKandwal
      wrote on last edited by
      #2

      Define the ID of file control as FileUpload then add a Button named as btnSubmit adn write the folowing code on the Button's onclick event private void btnSubmit_Click(object sender, System.EventArgs e) { try { if (isVaildData()) { if (FileUpload!=null) { string DestinationPath = Server.MapPath("../UpLoadFile/Images").ToString() ; string ImgName =GetUniqueId()+ System.IO.Path.GetFileName(FileUpload.PostedFile.FileName); ImgName = ImgName.Replace(" ", ""); string saveLoaction=DestinationPath+"\\"+ImgName; FileUpload.PostedFile.SaveAs(saveLoaction); Session["SavedFile"]=ImgName; btnSubmit.Enabled=false; btnRemoveFile.Enabled=true; lblMessage.Text="File :" + ImgName + " Uploaded Successfully "; lblMessage1.Text=ImgName; Session["strFileType"]=Request.QueryString["Type"].ToString().Trim(); } else lblMessage.Text="Please Browse a File."; } } catch(Exception ex) { string str=ex.Message; } } rivate Boolean isVaildData() { if (FileUpload.PostedFile.ContentLength==0) { lblMessage.Text="Please Select an valid file"; return false; } if ( FileUpload.PostedFile.FileName!="" ) { string filename=System.IO.Path.GetFileName(FileUpload.PostedFile.FileName.ToString()); string extension = System.IO.Path.GetExtension(FileUpload.PostedFile.FileName); string Type = Request.QueryString["Type"].ToString(); switch(extension.ToLower()) { case ".pdf": break; case ".doc": break; case ".jpg": break; case ".gif": break; default: { lblMessage.Text="Invalid Disclosures file :-" + FileUpload.PostedFile.FileName; return false; } } } return true; } Neeraj

      P 2 Replies Last reply
      0
      • N NKandwal

        Define the ID of file control as FileUpload then add a Button named as btnSubmit adn write the folowing code on the Button's onclick event private void btnSubmit_Click(object sender, System.EventArgs e) { try { if (isVaildData()) { if (FileUpload!=null) { string DestinationPath = Server.MapPath("../UpLoadFile/Images").ToString() ; string ImgName =GetUniqueId()+ System.IO.Path.GetFileName(FileUpload.PostedFile.FileName); ImgName = ImgName.Replace(" ", ""); string saveLoaction=DestinationPath+"\\"+ImgName; FileUpload.PostedFile.SaveAs(saveLoaction); Session["SavedFile"]=ImgName; btnSubmit.Enabled=false; btnRemoveFile.Enabled=true; lblMessage.Text="File :" + ImgName + " Uploaded Successfully "; lblMessage1.Text=ImgName; Session["strFileType"]=Request.QueryString["Type"].ToString().Trim(); } else lblMessage.Text="Please Browse a File."; } } catch(Exception ex) { string str=ex.Message; } } rivate Boolean isVaildData() { if (FileUpload.PostedFile.ContentLength==0) { lblMessage.Text="Please Select an valid file"; return false; } if ( FileUpload.PostedFile.FileName!="" ) { string filename=System.IO.Path.GetFileName(FileUpload.PostedFile.FileName.ToString()); string extension = System.IO.Path.GetExtension(FileUpload.PostedFile.FileName); string Type = Request.QueryString["Type"].ToString(); switch(extension.ToLower()) { case ".pdf": break; case ".doc": break; case ".jpg": break; case ".gif": break; default: { lblMessage.Text="Invalid Disclosures file :-" + FileUpload.PostedFile.FileName; return false; } } } return true; } Neeraj

        P Offline
        P Offline
        Pradip Kishore
        wrote on last edited by
        #3

        Hi Neeraj thanks a lot for your vital support. can you post a vb.net version of the code as i am using vb.net as my code behind.. thanks again

        pradip kishore

        1 Reply Last reply
        0
        • N NKandwal

          Define the ID of file control as FileUpload then add a Button named as btnSubmit adn write the folowing code on the Button's onclick event private void btnSubmit_Click(object sender, System.EventArgs e) { try { if (isVaildData()) { if (FileUpload!=null) { string DestinationPath = Server.MapPath("../UpLoadFile/Images").ToString() ; string ImgName =GetUniqueId()+ System.IO.Path.GetFileName(FileUpload.PostedFile.FileName); ImgName = ImgName.Replace(" ", ""); string saveLoaction=DestinationPath+"\\"+ImgName; FileUpload.PostedFile.SaveAs(saveLoaction); Session["SavedFile"]=ImgName; btnSubmit.Enabled=false; btnRemoveFile.Enabled=true; lblMessage.Text="File :" + ImgName + " Uploaded Successfully "; lblMessage1.Text=ImgName; Session["strFileType"]=Request.QueryString["Type"].ToString().Trim(); } else lblMessage.Text="Please Browse a File."; } } catch(Exception ex) { string str=ex.Message; } } rivate Boolean isVaildData() { if (FileUpload.PostedFile.ContentLength==0) { lblMessage.Text="Please Select an valid file"; return false; } if ( FileUpload.PostedFile.FileName!="" ) { string filename=System.IO.Path.GetFileName(FileUpload.PostedFile.FileName.ToString()); string extension = System.IO.Path.GetExtension(FileUpload.PostedFile.FileName); string Type = Request.QueryString["Type"].ToString(); switch(extension.ToLower()) { case ".pdf": break; case ".doc": break; case ".jpg": break; case ".gif": break; default: { lblMessage.Text="Invalid Disclosures file :-" + FileUpload.PostedFile.FileName; return false; } } } return true; } Neeraj

          P Offline
          P Offline
          Pradip Kishore
          wrote on last edited by
          #4

          Hi Neeraj another small task for you suppose i uploaded a file and i want to give a link of it for the user on a page.so how the user link can be automatically created on a user interface when i will upload a page..?

          pradip kishore

          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