Step 1. Import these two namespaces in your application. If you don't have an application, create a new Web application using Visual Studio and C#.
using System.IO;
using System.Net;
Step 2. Add a Upload File control and a button to the default WebForm.
Step 3. Write this code on the button click event handler. This code converts the selected image into a byte array and saves that into a text file.
- protected void Button1_Click(object sender, EventArgs e)
- {
- string str = FileUpload1.FileName.ToString();
- FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Images/" + str.ToString()));
- byte[] imgbyte =File.ReadAllBytes(Server.MapPath("~/Images/" + str.ToString()));
- File.WriteAllBytes(Server.MapPath("~/Images/image1.txt"), imgbyte);
- }
For more details, download the zip code.
Thanks