Skip to main content
edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
Removed tag from title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Faster file lookup in c#

I'm polling aan ashx handler to check if a specific file is present and return true or false depending on it.

Code:

 public void ProcessRequest(HttpContext context)  {   int myId;   if (context.IsRequestClean())   {   if (int.TryParse(context.Request["id"], out myId))   {   var directory = Directory.GetDirectories(context.Server.MapPath("~/App_Data/Files"), "*" + myId, SearchOption.TopDirectoryOnly);   if (directory.Length > 0)   {   if (Convert.ToInt32(directory[0][directory[0].Length - 1].ToString()) == myId)   {   context.Response.ContentType = "text/plain";   context.Response.Write("true");   }   }   }   }  } 

How can I speed the above up?

Faster file lookup in c#

I'm polling a ashx handler to check if a specific file is present and return true or false depending on it.

Code:

 public void ProcessRequest(HttpContext context)  {   int myId;   if (context.IsRequestClean())   {   if (int.TryParse(context.Request["id"], out myId))   {   var directory = Directory.GetDirectories(context.Server.MapPath("~/App_Data/Files"), "*" + myId, SearchOption.TopDirectoryOnly);   if (directory.Length > 0)   {   if (Convert.ToInt32(directory[0][directory[0].Length - 1].ToString()) == myId)   {   context.Response.ContentType = "text/plain";   context.Response.Write("true");   }   }   }   }  } 

How can I speed the above up?

Faster file lookup

I'm polling an ashx handler to check if a specific file is present and return true or false depending on it.

public void ProcessRequest(HttpContext context) { int myId; if (context.IsRequestClean()) { if (int.TryParse(context.Request["id"], out myId)) { var directory = Directory.GetDirectories(context.Server.MapPath("~/App_Data/Files"), "*" + myId, SearchOption.TopDirectoryOnly); if (directory.Length > 0) { if (Convert.ToInt32(directory[0][directory[0].Length - 1].ToString()) == myId) { context.Response.ContentType = "text/plain"; context.Response.Write("true"); } } } } } 

How can I speed the above up?

edited title
Link
Amit Joki
  • 265
  • 1
  • 6

Speed up responding time in a ashx handler while searching for a Faster file lookup in c#

Source Link
Amit Joki
  • 265
  • 1
  • 6
Loading