ASP Forum
Error when building Website
stimpy | Posted 1:26pm 20. September 2007 Server Time |

I'm in the middle of building my website and I decided it would be nice to have some photo albums, so I decided to add the ones from the Personal Website starter kit and just adjust the markup to fit my site layout.

All the pages the user would use to display them work fine and all the pages except on in the administration portion also work. The one I can't get to work is the Photos.aspx in the Admin section. I get the following error:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0030: Cannot convert type 'System.IO.FileInfo' to 'FileInfo'

Source Error:

Line 23:     {
Line 24:         DirectoryInfo d = new DirectoryInfo(Server.MapPath("~/Upload"));
Line 25:         foreach (FileInfo f in d.GetFiles("*.jpg"))
Line 26:         {
Line 27:             byte[] buffer = new byte[f.OpenRead().Length];


Source File: c:\Documents and Settings\jallen\My Documents\Visual Studio 2005\Websites\ContinuingEd\admin\photogallery\Photos.aspx.cs    Line: 25

and I made sure I copied the code behind exactly.

Anybody got any idea why only this page won't work and what I can do to fix it? I kind of need this page as its the one that lets you edit the captions for the photos.

Here's the actual code for the codebehind file:
using System;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.OleDb;
using System.IO;


public partial class admin_photogallery_Photos : System.Web.UI.Page
{

    protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        if (((Byte[])e.Values["BytesOriginal"]).Length == 0) e.Cancel = true;
    }

    protected void Button1_Click(object sender, ImageClickEventArgs e)
    {
        DirectoryInfo d = new DirectoryInfo(Server.MapPath("~/Upload"));
        foreach (FileInfo f in d.GetFiles("*.jpg"))
        {
            byte[] buffer = new byte[f.OpenRead().Length];
            f.OpenRead().Read(buffer, 0, (int)f.OpenRead().Length);
            PhotoManager.AddPhoto(Convert.ToInt32(Request.QueryString["AlbumID"]), f.Name, buffer);
        }
        GridView1.DataBind();
    }

}

ANy help or advice is greatly appreciated.
hotwu | Posted 4:29pm 20. September 2007 Server Time |

Try using the fully qualified path to FileInfo:

foreach (System.IO.FileInfo f in d.GetFiles("*.jpg")) ~ although I do not see there being a class conflict in the namespaces listed. Alternatively just reboot and rebuild your application, see if that takes care of it.
stimpy | Posted 5:25pm 20. September 2007 Server Time |

THanks hotwu... the reboot seemed to fix everything...


Reply to Post Error when building Website



Back to Forum Page