I have made something like the following code:
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["loginid"].ToString();
}
protected void delete_click(object sender, EventArgs e)
{
delete("mail1",Session["loginid"]);
}
private int delete(string mailid, string user)
{
System.IO.Directory.Delete(Server.MapPath(@"~\files\" + user + @"\" + mailid), true);
}
When i press the delete button, everything works fine and the folder gets deleted. but after that when page postbacks again then a NullRefrenceException is raised at Label1.Text = Session["loginid"].ToString();
why is it happening...??
When I am not using this Directory.Delete() method everything is working fine and session variables are not set to null.
When I traced my application I found that After Directory.Delete() method Session variables were intact and I was able to use those session variables in the processing after Directory.Delete().
But as soon as the page postbacks all session variables are set to null. And this problem doesn't appear when i m not using this delete() method.
The folder I m deleting is in my project's folder. I m running this website using Visual Studio.
Please help.