Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two websites the first website consist of inserting data and displaying it in a gridview in same page.

1.) The first website has a file upload feature which allows only image path is stored in server and image is stored in a folder named AgentImages/ID(created dynamically)/
that is with the website along with all the other folders like appcode and bin etc.

the coding of that website i.e. npay.in/nagent/ is here: this is submit code:

C#
protected void btnSubmit_Click(object sender, EventArgs e)
    {
         
        int id = Convert.ToInt32(Session["AgentMasterID"]);
        string temp = "";
        if (fuProducImage.HasFile)
        {
            if (CheckFileType() == true)
            {
                
                
                string ext1 = Path.GetExtension(fuProducImage.FileName);
                var query = (from c in agb.AgentProducts orderby c.AgentProductID descending select c.AgentProductID).First();
                int lastid = Convert.ToInt32(query);
                int last = lastid + 1;
                string directoryPath = Server.MapPath("../AgentImages/") + id;
                string vitualp = directoryPath.Replace(directoryPath, "~/AgentImages/").Replace(@"\", "/");
                string filepath = vitualp +id  + "/";
                if (!Directory.Exists(filepath))
                {

                    Directory.CreateDirectory(HttpContext.Current.Server.MapPath(filepath + "/"));
                    fuProducImage.SaveAs(MapPath(filepath +last + ext1));
                    temp = filepath  + last + ext1;
                }
                else
                {
                    fuProducImage.SaveAs(Server.MapPath(filepath + last + ext1));
                    temp = filepath + last + ext1;
                }
                //fuProducImage.SaveAs(MapPath("~/AgentImages/" + fuProducImage.FileName));  
            }
        }
        dmp.Product = txtProduct.Text;
        dmp.AgentMasterID = Convert.ToInt32(Session["AgentMasterID"]);
        dmp.Description = txtDescription.Text;
        dmp.Features = txtFeatures.Text;
        dmp.ProductMRP = Convert.ToDecimal(txtMRP.Text);
        dmp.ProductProfit = Convert.ToDecimal(txtProfit.Text);
        dmp.ProductSellingPrice = Convert.ToDecimal(txtSellingprice.Text);
        dmp.ProductImage = temp;
        //if (!IsPostBack)
        //{
            dmp.InsertAgentproduct();
        //}
        lblPimage.Visible = true;
        lblPimage.Text = "Data Inserted Sucesfully";
        displayproduct();


now i have another website having address npay.in/tbooking/products/

this website dosent cantain agentimage folder like the first website..

this page have a data list that displays product details that were inserted in first websit now my problem is the images arent getting fetched my code file for datalist is as bellow:



C#
protected void Page_Load(object sender, EventArgs e)
   {
       var query = from c in db.AgentProducts orderby c.AgentProductID descending where c.AgentMasterID == 2 && c.IsDeleted == false select c;
       DataList1.DataSource = query;
       DataList1.DataBind();
   }
   protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
   {
       Response.Redirect("ProductDetails.aspx?apid676quetro=" + DataList1.SelectedValue.ToString() + "");
   }


the images arent getting displayed please help me on that or tellme how else can i do it?? pls..
Posted
Updated 18-Jan-15 18:31pm
v2

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