Aliendreamer

a simple method for the webserver

Oct 8th, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.55 KB | None | 0 0
  1.   private IHttpResponse ReturnIfResource(string path)
  2.         {
  3.              //<script src="/resources/js/jquery-3.3.1.min.js"></script>
  4.             string pathTofile = $"../../..{path}";
  5.             bool fileExist = File.Exists(pathTofile);
  6.             if (!fileExist) return new HttpResponse(HttpResponseStatusCode.NotFound);
  7.  
  8.             string fileToBytes = File.ReadAllText(pathTofile);
  9.             var bytesTransform = Encoding.UTF8.GetBytes(fileToBytes);
  10.             return new InlineResourceResult(bytesTransform, HttpResponseStatusCode.Found);
  11.         }
Advertisement
Add Comment
Please, Sign In to add comment