Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Server Error in '/' Application.
--------------------------------------------------------------------------------

The resource cannot be found. 
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

Requested URL: /Admin/~Admin/AddNewProducts.aspx


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408 


Source code
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ShoppingProject.BusinessLayer;
 
namespace ShoppingProject.Admin
{
    public partial class AddNewProducts : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetCategories();
 
                AddSubmitEvent();
 
                if (Request.QueryString["alert"] == "success")
                {
                    Response.Write("<script>alert('Record Saved Successfully.');</script>");
                }
            }
 
        }
 
        private void AddSubmitEvent()
        {
            UpdatePanel updatePanel = Page.Master.FindControl("AdminUpdatePanel") as UpdatePanel;
            UpdatePanelControlTrigger trigger = new PostBackTrigger();
            trigger.ControlID = btnSubmit.UniqueID;
 
            updatePanel.Triggers.Add(trigger);
        }
 
        private void GetCategories()
        {
            ShoppingCart k = new ShoppingCart();
            DataTable dt = k.GetCategories();
            if (dt.Rows.Count > 0)
            {
                ddlCategory.DataValueField = "CategoryID";
                ddlCategory.DataTextField = "CategoryName";
                ddlCategory.DataSource = dt;
                ddlCategory.DataBind();
            }
        }
 
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (uploadProductPhoto.PostedFile != null)
            {
                SaveProductPhoto();
 
                ShoppingCart k = new ShoppingCart()
                {
                    ProductName = txtProductName.Text,
                    ProductPrice = txtProductPrice.Text,
                    ProductImage = "~/ProductImages/" + uploadProductPhoto.FileName,
                    ProductDescription = txtProductDescription.Text,
                    CategoryID = Convert.ToInt32(ddlCategory.SelectedValue),
                    TotalProducts = Convert.ToInt32(txtProductQuantity.Text)
                };
                k.AddNewProduct();
                // Alert.Show("Record Seved Successfully");
                ClearText();
                Response.Redirect("~Admin/AddNewProducts.aspx?alert=success");
 
            }
            else
            {
                //Alert.Show("Upload Product Photo");
                Response.Write("<script>alert('Please UpLoad Photo');</script>");
            }
 
        }
 
        private void ClearText()
        {
            uploadProductPhoto = null;
            txtProductName.Text = string.Empty;
            txtProductPrice.Text = string.Empty;
            txtProductDescription.Text = string.Empty;
            txtProductQuantity.Text = string.Empty;
        }
 
        private void SaveProductPhoto()
        {
            if (uploadProductPhoto.PostedFile != null)
            {
                string filename = uploadProductPhoto.PostedFile.FileName.ToString();
                string fileExt = System.IO.Path.GetExtension(uploadProductPhoto.FileName);
 
                //check file name length
                if (filename.Length > 96)
                {
                    //Alert.Show("image name should not exceed 96 character !");
                }
                //check filetype
                else if (fileExt != ".jpeg" && fileExt != ".jpg" && fileExt != ".png" && fileExt != ".bmp")
                {
                    //Alert.Show("Only jpeg,jpg,bmp & png imags are allowed!");
                }
 
                //check file size
                else if (uploadProductPhoto.PostedFile.ContentLength > 4000000)
                {
                    //Alert.Show("image size should not be greater than 4MB !");
                }
                //Save images into Images folder
                else
                {
                    uploadProductPhoto.SaveAs(Server.MapPath("~/ProductImages/" + filename));
                }
 
            }
        }
    }
}
Posted
Updated 9-Jan-16 4:06am
v2

1 solution

The problem would be somewhere with the URL itself. You have made sure that the page does exist, but not at the location specified. The location that you are trying to access is, "/Admin/~Admin/AddNewProducts.aspx". So in that location, are you sure, second "~Admin/" is required?

What I think is a valid URL would be something like this: "/Admin/AddNewProducts.aspx". Make sure that the files exist at the location. ASP.NET won't bother adding or removing directories for you. That is not what it does.
 
Share this answer
 
Comments
Muhammadkarim 10-Jan-16 5:06am    
Firstly thank you for your attention!!!
Above in my code, I'm typing
Response.Redirect("~Admin/AddNewProducts.aspx?alert=success");
Muhammadkarim 10-Jan-16 5:09am    
However,still it isn't working ?
Afzaal Ahmad Zeeshan 10-Jan-16 5:17am    
The problem would only be with the URL. Make sure that the file does exist.
Sabareddy Jai bheem 13-Sep-21 10:16am    
Sir hostel application my hakakantivi server busy antha torisakantha why

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