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 Uploading from the user?

File Uploading from the user?

Scheduled Pinned Locked Moved ASP.NET
question
7 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.
  • M Offline
    M Offline
    MudkiSekhon
    wrote on last edited by
    #1

    I am developing an application in which I have to ask the user to upload some file (of .jpg,.gif or .bmp formats). I want to store that file in a directory in my root directory of the application. I need to create a special folder for each user in that folder and paste those files uploaded from the user. Plz send me some sample code if u have any or just send me some suggestion of the classes and functions to be used. Thanks, Sandy

    J R 2 Replies Last reply
    0
    • M MudkiSekhon

      I am developing an application in which I have to ask the user to upload some file (of .jpg,.gif or .bmp formats). I want to store that file in a directory in my root directory of the application. I need to create a special folder for each user in that folder and paste those files uploaded from the user. Plz send me some sample code if u have any or just send me some suggestion of the classes and functions to be used. Thanks, Sandy

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      File Upload Web Control[^] Directory.CreateDirectory[^] Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

      M 1 Reply Last reply
      0
      • J J4amieC

        File Upload Web Control[^] Directory.CreateDirectory[^] Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour

        M Offline
        M Offline
        MudkiSekhon
        wrote on last edited by
        #3

        But FileUpload class is present only in .NET 2.0 whereas I am using 1.1 version for my whole project. Plz tell me the method to do it in .NET 1.1 framework Thanks, Sandy

        1 Reply Last reply
        0
        • M MudkiSekhon

          I am developing an application in which I have to ask the user to upload some file (of .jpg,.gif or .bmp formats). I want to store that file in a directory in my root directory of the application. I need to create a special folder for each user in that folder and paste those files uploaded from the user. Plz send me some sample code if u have any or just send me some suggestion of the classes and functions to be used. Thanks, Sandy

          R Offline
          R Offline
          R Prabha Devi
          wrote on last edited by
          #4

          Try the below code,It is working in .Net 1.1 //uploading files control System.Web.UI.HtmlControls.HtmlInputFile ctlImageInput; //Declarations string strFileName; string strFilePath; string strFolder; //u can use the unique user name for all the folders strFolder = AppDomain.CurrentDomain.BaseDirectory + "Images/username"; // Creating Directory if ((!(Directory.Exists(strFolder)))) { Directory.CreateDirectory(strFolder); } //Saving source file to destination if( ctlImageInput.Value !="") { strFileName = ctlImageInput.PostedFile.FileName; strFileName = Path.GetFileName(strFileName); strFilePath = strFolder + "/"+ strFileName; ctlImageInput.PostedFile.SaveAs(strFilePath); }

          M 2 Replies Last reply
          0
          • R R Prabha Devi

            Try the below code,It is working in .Net 1.1 //uploading files control System.Web.UI.HtmlControls.HtmlInputFile ctlImageInput; //Declarations string strFileName; string strFilePath; string strFolder; //u can use the unique user name for all the folders strFolder = AppDomain.CurrentDomain.BaseDirectory + "Images/username"; // Creating Directory if ((!(Directory.Exists(strFolder)))) { Directory.CreateDirectory(strFolder); } //Saving source file to destination if( ctlImageInput.Value !="") { strFileName = ctlImageInput.PostedFile.FileName; strFileName = Path.GetFileName(strFileName); strFilePath = strFolder + "/"+ strFileName; ctlImageInput.PostedFile.SaveAs(strFilePath); }

            M Offline
            M Offline
            MudkiSekhon
            wrote on last edited by
            #5

            But I don't have .NET 2.0 and I want to bring the file from client's computer to my server. Whenever I use the above code , it says object reference not set to an instance of an object. In Html code I had taken, Thanks, Sandy

            1 Reply Last reply
            0
            • R R Prabha Devi

              Try the below code,It is working in .Net 1.1 //uploading files control System.Web.UI.HtmlControls.HtmlInputFile ctlImageInput; //Declarations string strFileName; string strFilePath; string strFolder; //u can use the unique user name for all the folders strFolder = AppDomain.CurrentDomain.BaseDirectory + "Images/username"; // Creating Directory if ((!(Directory.Exists(strFolder)))) { Directory.CreateDirectory(strFolder); } //Saving source file to destination if( ctlImageInput.Value !="") { strFileName = ctlImageInput.PostedFile.FileName; strFileName = Path.GetFileName(strFileName); strFilePath = strFolder + "/"+ strFileName; ctlImageInput.PostedFile.SaveAs(strFilePath); }

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

              public class Uploadphoto : System.Web.UI.Page { protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Label Label1; string strPath; private void Page_Load(object sender, System.EventArgs e) { long ID = 8; // long PropertyID = long.Parse(Request.QueryString["id"]); string appPath = Server.MapPath("Photos"); strPath = appPath + "\\" + ID.ToString(); System.IO.Directory.CreateDirectory(strPath); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button1_Click(object sender, System.EventArgs e) { string strFile = Request.Form["inpFile"].ToString(); string strFileName = strFile.Substring(strFile.LastIndexOf("\\")+1,strFile.Length-(strFile.LastIndexOf("\\")+1)); File.Copy(Request.Form["inpFile"],strPath + "\\" + strFileName); } } and my HTML code is Uploadphoto

              You can only add files with .jpg,.gif or .bmp extensions

              The problem is that when I click the Upload button after browsing and selecting a file in FileInput control, I get the following exception Exception Details: System.IO.FileNotFoundException: Could not

              R 1 Reply Last reply
              0
              • M MudkiSekhon

                public class Uploadphoto : System.Web.UI.Page { protected System.Web.UI.WebControls.Button Button1; protected System.Web.UI.WebControls.Label Label1; string strPath; private void Page_Load(object sender, System.EventArgs e) { long ID = 8; // long PropertyID = long.Parse(Request.QueryString["id"]); string appPath = Server.MapPath("Photos"); strPath = appPath + "\\" + ID.ToString(); System.IO.Directory.CreateDirectory(strPath); } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.Button1.Click += new System.EventHandler(this.Button1_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void Button1_Click(object sender, System.EventArgs e) { string strFile = Request.Form["inpFile"].ToString(); string strFileName = strFile.Substring(strFile.LastIndexOf("\\")+1,strFile.Length-(strFile.LastIndexOf("\\")+1)); File.Copy(Request.Form["inpFile"],strPath + "\\" + strFileName); } } and my HTML code is Uploadphoto

                You can only add files with .jpg,.gif or .bmp extensions

                The problem is that when I click the Upload button after browsing and selecting a file in FileInput control, I get the following exception Exception Details: System.IO.FileNotFoundException: Could not

                R Offline
                R Offline
                R Prabha Devi
                wrote on last edited by
                #7

                The earlier code will work to complete ur requirement Declare a control as server control by below code Now try..:) -- modified at 8:35 Tuesday 25th April, 2006

                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