<%@ WebHandler language= "C #" class= "Imagemanager"%> /** * Created by Visual studio2010 * User:xuheng * date:12-3-7 * Time: 16:29 * To change this template use File | Settings | File Templates. */ Using System; Using System.Web; Using System.IO; Using System.Text.RegularExpressions; public class Imagemanager:ihttphandler { public void ProcessRequest (HttpContext context) { Context. Response.ContentType = "Text/plain";
String[] paths = {"Upload", "Upload1"}; A list of directories that need to be traversed, preferably with a thumbnail address, or it can cause serious delays when the network is slow string[] filetype = {". gif", ". png", ". jpg", ". jpeg", ". bmp"}; File Allow format String action = context. Server.HTMLEncode (context. Request["Action"]); if (action = "Get") { String str = String.Empty;
foreach (string path in Paths) { DirectoryInfo info = new DirectoryInfo (context. Server.MapPath (path)); Directory validation if (info. Exists) { directoryinfo[] Infoarr = info. GetDirectories (); foreach (DirectoryInfo tmpinfo in Infoarr) { foreach (FileInfo fi in Tmpinfo.getfiles ()) { if (array.indexof, filetype, fi. Extension)!=-1) { STR + + path+ "/" + Tmpinfo.name + "/" + FI. Name + "Ue_separate_ue"; } } } } }
Context. Response.Write (str); } ADD start========================================================== 2013-05-12 Delete the selected files String Pathdel = String. Empty; It is best to use a thumbnail address, otherwise it can cause severe delay when the network speed is slow String fileName = context. Server.HTMLEncode (context. request["FileName"]); BOOL isdeleted = false; if (action = "Del") { Try {
String fullpath = String.Empty; foreach (string path in Paths) { Pathdel = context. Server.MapPath (path); DirectoryInfo info = new DirectoryInfo (Pathdel); Directory validation if (info. Exists) { Get the C:...ueditornetupload directory in the time named directory. such as: 2013-05-12 directoryinfo[] Infoarr = info. GetDirectories (); foreach (DirectoryInfo tmpinfo in Infoarr) { foreach (FileInfo fi in Tmpinfo.getfiles ()) { Determines whether the specified picture type, because the attachment and picture of the long pass are in the same directory if (array.indexof, filetype, fi. Extension)!=-1) { if (FI. Name.equals (FileName)) { FullPath = Pathdel + "/" + Tmpinfo.name + "/" + fileName; File.delete (FullPath); IsDeleted = true; Break } } } has been removed, jumped out if (isdeleted = = True) Break } } has been removed, jumped out if (isdeleted = = True) Break } IsDeleted = false; Context. Response.Write ("Success"); } Catch { Context. Response.Write ("error"); } } ADD end============================================================ 2013-05-12 } public bool IsReusable { Get { return false; } } } |