Using system. IO;
Protected void readfile () // read the folder, file
...{
String savepath = @ "packnetproductimg ";
String abssavepath = server. mappath (savepath );
String [] directorys = directory. getdirectories (abssavepath + @ "/" + Page. User. Identity. Name );
For (INT I = 0; I <directorys. length; I ++)
...{
Response. Write (directorys [I] + "<br/> ");
}
Response. Write ("directorys count:" + directorys. Length + "<br/> --------- <br> ");
String [] files = directory. getfiles (abssavepath + @ "" + Page. User. Identity. Name ,"*");
For (INT I = 0; I <files. length; I ++)
...{
Response. Write (files [I] + "<br/> ");
}
Response. Write ("files count:" + files. Length + "<br/> --------- <br> ");
}
protected void button#click (Object sender, eventargs e) // upload an image
... {
string savepath = "/packnet/productimg";
string abssavepath = server. mappath (savepath);
If (! Directory. exists (abssavepath)
directory. createdirectory (abssavepath);
If (! Directory. exists (abssavepath + @ "" + Page. user. identity. name)
directory. createdirectory (abssavepath + @ "" + Page. user. identity. name);
If (this. picfile. postedfile. contentlength <100)
... {
response. write (" ");
return;
}
If (this. picfile. postedfile. contentlength> 500000)
... {
response. Write (" ");
return;
}
String clientfilename = This. picfile. postedfile. filename;
String exname = clientfilename. substring (clientfilename. lastindexof ('.'). tolower ();
If (exname! = ". BMP" & exname! = ". Jpg" & exname! = ". GIF ")
...{
Response. Write ("<SCRIPT> alert ('file format Error !! '); </SCRIPT> ");
Return;
}
String filename = guid. newguid (). tostring ();
Filename + = exname;
This. picfile. postedfile. saveas (abssavepath + @ "/" + Page. User. Identity. Name + @ "/" + filename );
}
ArticleSource: http://www.diybl.com/course/4_webprogram/asp.net/netjs/20071020/78354.html