namespace WebApplication4
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (upImage.HasFile)
            {
                if (CheckFileType(upImage.FileName))
                {
                    string fielPath = " !/UploadImages/" + upImage.FileName;
                    upImage.SaveAs(MapPath(filePath));
                }

            }

        }


        bool CheckFileType(string fileName)
{
    string ext = Path.GetExtension ( fileName);
    switch (ext.ToLower()) 
{
    case ".gif" :
    return true; 
    case ".png:" :
    return true;
        case ".jpg" :
    return true;
    case " .jpeg" : 
    return true ;
    default :
    return false ; 
}
}
        void Page_Prerender()
        {
            string upFodler = MapPath("~/UploadImages/");
            DirectoryInfo dir = new DirectoryInfo(upFolder);
            dlstImages.DataSouce = dir.GetFiles();
            dlstImages.DataBind();

        }
    }
}

Error 1 The name 'filePath' does not exist in the current context C:\Users\se7olutionyg\Documents\Visual Studio 2008\Projects\WebApplication4\WebApplication4\Default.aspx.cs 30 44 WebApplication4

this is from the text book, i understand how the system work , but don't know what do they means by filePath
Is that the way we declare the path where the pix are located
second, can anybody explain the keyword,
DirectoryInfo,DirectoryInfo(upFolder);
DataSouce

Recommended Answers

All 3 Replies

Spelling mistake in the variable declaration 'string fielPath'.

Change line 16 in your code as below

string filePath = " !/UploadImages/" + upImage.FileName;
void Page_Prerender()
        {
            string upFodler = MapPath("~/UploadImages/");
            DirectoryInfo dir = new DirectoryInfo(upFolder);
            dlstImages.DataSouce = dir.GetFiles();
            dlstImages.DataBind();

how about those stuff?
what should i put in directory info,
datasource,
is taht the source of the image file or what?

Yes its a datasource. It will enlist all files under the folder specified in first line.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.