Folder listing and permissions
I have an aspx page that is displaying the contents of a directory on my web server. Each folder has different permissions based on user log ons. My problem is this. . .
I do not want to display folders in which users do not have permission to. Is there a way to do this?
Here is the code . . .
C#
public void Page_Load(object s, System.EventArgs ea) {
try {
string strDir = Request.QueryString["d"];
string strParent = strDir.Substring(0,strDir.LastIndexOf("\\"));
strParent += strParent.EndsWith(":") ? "\\" : "";
upLink.NavigateUrl = "browse.aspx?d="+strParent;
txtCurrentDir.Text = "Address: <b>"+strDir + "</b>";
DirectoryInfo DirInfo = new DirectoryInfo(strDir);
DirectoryInfo[] subDirs = DirInfo.GetDirectories();
FileInfo[] Files = DirInfo.GetFiles();
txtListing.Text = "<table>";
for (int i=0; i<=subDirs.Length-1; i++) {
txtListing.Text +="Check auth here";
txtListing.Text += "<tr><td><img src='images/folder.gif'><a href='browse.aspx?d="+subDirs[i].FullName+"' class='entry'>"+subDirs[i].Name+"</a></td><td valign='bottom'>"+subDirs[i].LastWriteTime+"</td></tr>";
}
for (int i=0; i<=Files.Length-1; i++) {
txtListing.Text += "<tr><td><img src='images/file.gif'>"+Files[i].Name+"</td><td valign='bottom'>"+Files[i].LastWriteTime+"</td></tr>";
}
txtListing.Text += "</table>";
}
catch (UnauthorizedAccessException ex){
}
catch (Exception e){
txtListing.Text = "Error retrieving directory info: "+e;
}
}
|