Hi All,
I want to load an image(jpeg,png,..etc) from the hard disk and load it into image control in ASP.NET.
I prefer C# as the programming language.
After loading the image , i want to save the file location in a text file. Then the next time i can read the text file and i can get the image location[path]. I can do the same thing for the form application, but difficult to mange web applications[ASP.NET].
So simply what i need is; code segment for
-Browse an image file from the disk
-Load it into a image control[if resizing is possible, then good]
-then save the image location to a text file
can anybody help me to do this?
Thanks,
Charithmax
Loading

PJ MartinsRank #2,548 · 548 reputationPosted Jun 25, 2010, 6:24 AM EDT
Charith Liyanagamage112 reputationPosted Jun 25, 2010, 7:08 PM EDT
http://asp.net-tutorials.com/controls/file-upload-control/
this is the code segment....
--------------------File Upload Control--------------------------------------------------------------------------------------------
form id="form1" runat="server"> asp:FileUpload id="FileUploadControl" runat="server" /> asp:Button runat="server" id="UploadButton" text="Upload" onclick="UploadButton_Click" /> br />br /> asp:Label runat="server" id="StatusLabel" text="Upload status: " /> form> ------------------------------------------------------------------------------------------------- this is the program code.you can control the file size too.... :) protected void UploadButton_Click(object sender, EventArgs e) { if(FileUploadControl.HasFile) { try { if(FileUploadControl.PostedFile.ContentType == "image/jpeg") { if(FileUploadControl.PostedFile.ContentLength 102400) { string filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath("~/") + filename); StatusLabel.Text = "Upload status: File uploaded!"; } else StatusLabel.Text = "Upload status: The file has to be less than 100 kb!"; } else StatusLabel.Text = "Upload status: Only JPEG files are accepted!"; } catch(Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; } } } Thanks, Charith