File Uploading from the user?
-
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
-
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
File Upload Web Control[^] Directory.CreateDirectory[^] Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
-
File Upload Web Control[^] Directory.CreateDirectory[^] Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
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
-
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
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); }
-
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); }
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
-
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); }
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
-
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
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