Hi Everyone,
It has been a long time. Anyhow, I am writing this app that is suppose to
access a directory on the server and list all the directories files and bind
it to a Repeater control. This is the source or codebehind rather:
private void Page_Load(Object source, EventArgs e)
{
If(!Page.IsPostBack)
{
..
showDirectoryContents(Server.MapPath(Directory Path));
..
}
}
private void showDirectoryContents(string Path)
{
DirectoryInfo dir=new DirectoryInfo(Path);
FileInfo[] fileCollection=dir.GetFiles();
Repeater1.DataSource=fileCollection;
Repeater1.DataBind();
}
The error I am getting is as follows:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information abou
t
the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 210: DirectoryInfo dir=new DirectoryInfo(Path);
Line 211: FileInfo[] fileCollection=dir.GetFiles();
Line 212: Repeater1.DataSource=fileCollection; <--this line is the
source of the problem.
Line 213: Repeater1.DataBind();
Line 214: }
I've scripted the repeater control into the form as it should be and set the
id to Repeater1 so I don't know what I'm doing wrong. Can someone tell me
what I'm missing here?
Thank you.
Sam-Hi,
I am Sam wrote:
> Hi Everyone,
> It has been a long time. Anyhow, I am writing this app that is suppose to
> access a directory on the server and list all the directories files and bi
nd
> it to a Repeater control. This is the source or codebehind rather:
Do you have a aspx.designer.cs file under the ASPX file in the Solution
explorer? Sometimes (especially when porting a 1.1 application to 2.0),
the file is not generated automatically, and then the controls are not
created.
Two ways around that: Declare the "Repeater1" yourself in the code
behind (must be protected), or recreate the ASPX file, copy-paste the
controls inside it, compile and make sure that the designer.cs file is
generated correctly this time.
HTH,
Laurent
> private void Page_Load(Object source, EventArgs e)
> {
> If(!Page.IsPostBack)
> {
> ...
> showDirectoryContents(Server.MapPath(Directory Path));
> ...
> }
> }
> private void showDirectoryContents(string Path)
> {
> DirectoryInfo dir=new DirectoryInfo(Path);
> FileInfo[] fileCollection=dir.GetFiles();
> Repeater1.DataSource=fileCollection;
> Repeater1.DataBind();
> }
> The error I am getting is as follows:
> Object reference not set to an instance of an object.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information ab
out
> the error and where it originated in the code.
> Exception Details: System.NullReferenceException: Object reference not set
> to an instance of an object.
> Source Error:
>
> Line 210: DirectoryInfo dir=new DirectoryInfo(Path);
> Line 211: FileInfo[] fileCollection=dir.GetFiles();
> Line 212: Repeater1.DataSource=fileCollection; <--this line is the
> source of the problem.
> Line 213: Repeater1.DataBind();
> Line 214: }
> I've scripted the repeater control into the form as it should be and set t
he
> id to Repeater1 so I don't know what I'm doing wrong. Can someone tell me
> what I'm missing here?
> Thank you.
> Sam-
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
0 comments:
Post a Comment