WebService代碼:spa
private void GetDirectoryFiles() { string PageURL = contextW.Request.Form["PageURL"];//URL頁面 string role_str = Utility.Tool.GetStrRole(PageURL);//在該頁面的權限 if (!string.IsNullOrEmpty(role_str)) { string dir = contextW.Request.Form["dir"]; string dirPath = contextW.Server.MapPath(dir); if (System.IO.Directory.Exists(dirPath)) { List<string> list = new List<string>(); DirectoryInfo folder = new DirectoryInfo(dirPath); reGetFiles(folder, ref list, dir); Jayrock.Json.JsonTextWriter writer = new Jayrock.Json.JsonTextWriter(); Jayrock.Json.Conversion.JsonConvert.Export(list, writer); contextW.Response.Write(writer.ToString()); } else { contextW.Response.Write("0"); } } else { contextW.Response.Write("-1"); } contextW.ApplicationInstance.CompleteRequest(); } //獲取目錄下全部的文件(遞歸) private void reGetFiles(DirectoryInfo folder, ref List<string> list,string dir) { string dirPath = contextW.Server.MapPath(dir); //獲取此目錄下的文件 foreach (FileInfo file in folder.GetFiles()) { string newPath = dir + file.FullName.Replace(dirPath, "").Replace("\\", "/"); list.Add(newPath); } //獲取此目錄下的目錄 foreach (DirectoryInfo dirtemp in folder.GetDirectories()) { reGetFiles(dirtemp, ref list,dir); } }
dir=「/Words/」即獲取Words下全部文件相對路徑code