Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

am uploading the image in project...

while uploading..

Errors are occured

1.'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image'

2.'System.Web.UI.WebControls.Image' does not contain a definition for 'FromStream'


while uploding , i am reducing the size of image..

code
C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;

public partial class AdminControl : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Panel3.Visible = false;
            Bind();
            BindDataList();
        }
    }

    protected void BindDataList()
    {
        DirectoryInfo dir = new DirectoryInfo(MapPath("Images"));
        FileInfo[] files = dir.GetFiles();
        ArrayList listItems = new ArrayList();
        foreach (FileInfo info in files)
        {
            listItems.Add(info);
        }
        //dtlist.DataSource = listItems;
        //dtlist.DataBind();

    }

    protected void Bind()
    {
        con.Open();
        SqlCommand cmd = new SqlCommand("Select * from EanatomyCategory", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        con.Close();
        ddlanatomyCate.DataSource = dt;
        ddlanatomyCate.DataTextField = "AnatomyName";
        ddlanatomyCate.DataValueField = "ID";
        ddlanatomyCate.DataBind();
        ddlanatomyCate.Items.Insert(0, new ListItem("-Select Anatomy-", "0"));
    }


    public static int ID;
    public static string ICON;
    public static int Result;


    protected void lnkaddmore_Click(object sender, EventArgs e)
    {
        Panel4.Visible = false;
        Panel1.Visible = false;
        Panel3.Visible = true;
    }
    protected void btnSubmit1_Click(object sender, EventArgs e)
    {
        String extention;
        String name = iconuplaod.FileName;
        string filename2 = Path.GetFileName(ScreenShot1.PostedFile.FileName);
        String name1 = name.ToUpper();

        if (name1.EndsWith(".JPG"))
            extention = ".JPG";
        else if (name1.EndsWith(".GIF"))
            extention = ".GIF";
        else if (name1.EndsWith(".JPEG"))
            extention = ".JPEG";
        else if (name1.EndsWith(".gif"))
            extention = ".gif";
        else
            extention = "";


        String filename = Path.GetFileName(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Today.Minute.ToString() + DateTime.Now.Second.ToString() + extention);

        iconuplaod.SaveAs(Server.MapPath("Images/" + filename));
        ScreenShot1.SaveAs(Server.MapPath("ScreenShot/" + filename2));

        int CatId = ddlanatomyCate.SelectedIndex;
        con.Open();
        SqlCommand cmd = new SqlCommand("Insert into AdminMaster(ID,A_icon)values(@ID,@A_icon)", con);

        ID = CatId;
        ICON = filename;

        cmd.Parameters.AddWithValue("@ID", CatId);
        cmd.Parameters.AddWithValue("@A_icon", filename);
        cmd.ExecuteNonQuery();

        

        string targetPath = Server.MapPath("Images/" + filename);
        Stream strm = iconuplaod.PostedFile.InputStream;
        var targetFile = targetPath;
        //Based on scalefactor image size will vary
        GenerateThumbnails(0.5, strm, targetFile);
       

        //Find Last Inserted ID//

        cmd = new SqlCommand("Select @@Identity", con);
        Result = Convert.ToInt32(cmd.ExecuteScalar());

        SqlCommand cmd1 = new SqlCommand("Insert into AdminTransaction (A_id,ID,title,ScreenShot,Description)values(@A_id1,@ID1,@More_title1,@More_screenshot2,@More_desc2) ", con);
        cmd1.Parameters.AddWithValue("@A_id1", Result);
        cmd1.Parameters.AddWithValue("ID1", ID);
        cmd1.Parameters.AddWithValue("@More_title1", txttitle1.Text);
        cmd1.Parameters.AddWithValue("@More_screenshot2", filename2);
        cmd1.Parameters.AddWithValue("More_desc2", txtdesc1.Text);

        cmd1.ExecuteNonQuery();
        con.Close();
        //SavMoreDetails();
        clear();
    }

    // 
    private void GenerateThumbnails(double scaleFactor, Stream sourcePath, string targetPath)
    {
        using (var image = Image.FromStream(sourcePath))
        {
            var newWidth = (int)(160 * scaleFactor);
            var newHeight = (int)(160 * scaleFactor);
            var thumbnailImg = new Bitmap(newWidth, newHeight);
            var thumbGraph = Graphics.FromImage(thumbnailImg);
            thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
            thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
            thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
            var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
            thumbGraph.DrawImage(image, imageRectangle);
            thumbnailImg.Save(targetPath, image.RawFormat);
        }
    }
    protected void btnSubmit2_Click(object sender, EventArgs e)
    {
        SavMoreDetails();
        clear();
    }

    public void SavMoreDetails()
    {
        //string filename3 = Path.GetFileName(Screenshot2.PostedFile.FileName);
        string filename3 = Screenshot2.FileName;
        Screenshot2.SaveAs(Server.MapPath("ScreenShot/" + filename3));

        con.Open();

        SqlCommand cmd = new SqlCommand("Insert into AdminTransaction(A_id,ID,title,ScreenShot,Description)values(@A_id,@ID,@More_title,@More_screenshot1,@More_desc1) ", con);


        cmd.Parameters.AddWithValue("@A_id", Result);
        cmd.Parameters.AddWithValue("ID", ID);
        cmd.Parameters.AddWithValue("@More_title", txttiltel2.Text);
        cmd.Parameters.AddWithValue("@More_screenshot1", filename3);
        cmd.Parameters.AddWithValue("More_desc1", txtdesc2.Text);

        cmd.ExecuteNonQuery();
        con.Close();

    }

    public void clear()
    {
        txttitle1.Text = "";
        txtdesc1.Text = "";
        txttiltel2.Text = "";
        txtdesc2.Text = "";
    }



    protected void lnkaddmore1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Index.aspx");
    }
}
Posted
v3
Comments
StianSandberg 14-May-13 2:41am    
please add your code, and I'm sure someone can help you..
Dixit Ashish 14-May-13 2:43am    
ok..!
Sairam_Nagothu 14-Sep-15 6:56am    
good

'Image' is an ambiguous reference between 'System.Web.UI.WebControls.Image' and 'System.Drawing.Image' means that your code doesn't know which class you are refereng to in your code.
You can explicitly tell by declaring your variable using the whole path (namespace) to your class:

C#
using (var image = System.Drawing.Image.FromStream(sourcePath))
 
Share this answer
 
Comments
Dixit Ashish 14-May-13 2:57am    
but when i remove these namespace

using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

and

ddlanatomyCate.Items.Insert(0, new ListItem("-Select Anatomy-", "0"));

the project run properly...!!
  1. Don't write the type Image. Write the full name; either System.Web.UI.WebControls.Image or System.Drawing.Image, depending on which one you really need:
    http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.image.aspx[^],
    http://msdn.microsoft.com/en-us/library/system.drawing.image.aspx[^].
  2. This error is related to the error #1. If you really need the second of the two types and name it with it fully-qualified name, the will be recognized by the compiler correctly. It does have the method you tried to use:
    http://msdn.microsoft.com/en-us/library/93z9ee4x.aspx[^].


That's all. Unfortunately, you don't understand some of the .NET basics. Perhaps you need to make a step back and learn it all to get enough confidence, before getting back to ASP.NET development and other advanced things.

—SA
 
Share this answer
 
You can use a type alias...
Refer - Ambiguous Reference Between Two NameSpaces[^]
 
Share this answer
 
Comments
Dixit Ashish 14-May-13 3:08am    
Tadit Dash..

can i send you my project... i have your mail ID
Is the Error still there ? You just need to refer the correct namespace.
Dixit Ashish 14-May-13 3:32am    
when i remove these namespace

using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

and

ddlanatomyCate.Items.Insert(0, new ListItem("-Select Anatomy-", "0"));

the project run properly...!!
No don't remove them... When you want to use Image class, then instead of Image write the fully qualified name as System.Drawing.Image like below...

System.Drawing.Image.FromStream(sourcePath)

Are you getting it ?
Else. you can use an alias as in the link I have given in my answer. Please try and let me know.
Dixit Ashish 14-May-13 4:02am    
i did bt not workin...!! :(

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