G
Guest
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 about
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-
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 about
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-