Upload photo into image control
I want to upload photo and save it into the image control please tell how to do that program in asp.net.Like in C#.net dialog box will be there.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Scott LyslePosted Oct 12, 2008, 8:10 PM
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.IO;
namespace Uploader
{
///
/// This web method will provide an web method to load any
/// file onto the server; the UploadFile web method
/// will accept the report and store it in the local file system.
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class FileUploader : System.Web.Services.WebService
{
[WebMethod]
public string UploadFile(byte[] f, string fileName)
{
// the byte array argument contains the content of the file
// the string argument contains the name and extension
// of the file passed in the byte array
try
{
// instance a memory stream and pass the
// byte array to its constructor
MemoryStream ms = new MemoryStream(f);
// instance a filestream pointing to the
// storage folder, use the original file name
// to name the resulting file
FileStream fs = new FileStream
(System.Web.Hosting.HostingEnvironment.MapPath("~/TransientStorage/") +
fileName, FileMode.Create);
// write the memory stream containing the original
// file as a byte array to the filestream
ms.WriteTo(fs);
// clean up
ms.Close();
fs.Close();
fs.Dispose();
// return OK if we made it this far
return "OK";
}
catch (Exception ex)
{
// return the error message if the operation fails
return ex.Message.ToString();
}
}
}
}
Then take a look at this: http://www.vbdotnetheaven.com/UploadFile/scottlysle/ImageGallery11192006000024AM/ImageGallery.aspx?ArticleID=f0f1c3f2-4871-4bbd-afec-bdffac94c622