Click here to Skip to main content
15,867,964 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

namespace ImageEx
{
    public partial class UploadCrop : System.Web.UI.Page
    {
        String path = HttpContext.Current.Request.PhysicalApplicationPath + "images\\";
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            Boolean FileOK = false;
            Boolean FileSaved = false;
            {
                  Session["WorkingImage"] = Upload.FileName;
                String FileExtension = Path.GetExtension(Session["WorkingImage"].ToString()).ToLower();
                String[] allowedExtensions = { ".png", ".jpeg", ".jpg", ".gif" };
                for (int i = 0; i < allowedExtensions.Length; i++)
                {
                    if (FileExtension == allowedExtensions[i])
                    {
                        FileOK = true;
                    }
                }
            }

            if (FileOK)
            {
                try
                {
                    Upload.PostedFile.SaveAs(path + Session["WorkingImage"]);
                    FileSaved = true;
                }
                catch (Exception ex)
                {
                    LblError.Text = "File could not be uploaded." + ex.Message.ToString();
                    LblError.Visible = true;
                    FileSaved = false;
                }
            }
            else
            {
                LblError.Text = "Cannot accept files of this type.";
                LblError.Visible = true;
            }

            if (FileSaved)
            {
                pnlUpload.Visible = false;
                pnlCrop.Visible = true;
                imgCrop.ImageUrl = "images/" + Session["WorkingImage"].ToString();

            }


        }




    }
}

The above is my codebehind file
$('
<img src=" "
'))
.css
{//some code


}
Posted

1 solution

For the image src specify the full url to the image file.For eg: http://www.test.com/images/testimage.jpg. This will display the image
 
Share this answer
 
Comments
Member 10170389 8-Oct-13 3:14am    
Sir,instead of testimage.jpg,there i needed the dynamic path of the image..
In my project Iam uploading the file on images folder..<img src="~/images/......" />,i need to acess the name of the image

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900