Display new image on web page

Posted by RuiT on Stack Overflow See other posts from Stack Overflow or by RuiT
Published on 2010-03-10T15:41:22Z Indexed on 2010/03/15 0:49 UTC
Read the original article Hit count: 315

Filed under:
|

Hello,

I'm uploading images to a folder and I want to display each new image on a web page every time it is saved in the folder.

I can display the initial image, which is already in the folder, and I can also detect when a new image is saved into the folder but I don't know how to display the new images.

I'm new to web development. Can somebody help me?

Here's the code:

public partial class _Default : System.Web.UI.Page
{

    string DirectoryPath = "C:\\Users\\Desktop\\PhotoUpload\\Uploads\\";

    protected void Page_Load(object sender, EventArgs e)
    {

        FileSystemWatcher watcher = new FileSystemWatcher();

        try
        {
            watcher.Path = DirectoryPath;
            watcher.Created += new FileSystemEventHandler(watcher_Created);
            watcher.EnableRaisingEvents = true;

            Image image = Image.FromFile(DirectoryPath + "inicial.jpg");
            MemoryStream ms = new MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            byte[] im = ms.ToArray();

            Context.Response.ContentType = "Image/JPG";
            Context.Response.BinaryWrite(im);


        }
        catch (Exception ex)
        {
        }

    }

    void watcher_Created(object sender, FileSystemEventArgs e)
    {
        Console.WriteLine("File Created: Name: " + e.Name);

        try
        {

          //How to display new image?  


        }
        catch (Exception ex)
        {
        }
    }

}

© Stack Overflow or respective owner

Related posts about .NET

Related posts about ASP.NET