Problem with GetFiles

G

Guest

when i run the code below to search my entire c drive.. i get this following
error message:

Access to the path "c:\System Volume Information" is denied.
Line 29: foreach (string f in Directory.GetFiles(d, ".mp3"))
In web.config i have <identity impersonate="true"/>

When i run the same code in Windows Form it works fine, also i like to know
how i can put the results into an array instead of using response.write.

public class Search : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
DirSearch("c:\\");
}

public void DirSearch(string sDir){

foreach (string d in Directory.GetDirectories(sDir))
{
foreach (string f in Directory.GetFiles(d, ".mp3"))
{
Response.Write(f);
}
DirSearch(d);
}
}
 
K

Kevin Spencer

Windows Forms and other executables run under the System account. ASP.Net
runs under a different account, by default either ASPNET or Network Service,
with restricted privileges, for security reasons. You just need to grant
the necessary file IO permission to the account on your system under which
the ASP.Net worker process runs.
also i like to know
how i can put the results into an array instead of using response.write.

(Watch your bedside mannner, here, Kevin) Ummm. Directory.GetFiles() RETURNS
an array. And BTW, using Response.Write is really klugy with ASP.Net, which
is object-oriented.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top