Guest User

Untitled

a guest
Jan 24th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public class YOUR_CLASS_NAME {
  2.  
  3. private readonly IHostingEnvirounment _hostingEnvirounment;
  4.  
  5. public YOUR_CLASS_NAME(IHostingEnvironment hostingEnvironment)
  6. {
  7. _hostingEnvironment = hostingEnvironment;
  8. }
  9.  
  10. public Image GetImageFromContentRoot(string name) {
  11.  
  12. // e.g.: imgPath = "D:\Hosting\ProjectFolder\beep.png"
  13. var imgPath = Path.Combine(_hostingEnvirounment.ContentRootPath, name);
  14.  
  15. return Image.FromFile(imgPath);
  16. }
  17. }
  18.  
  19. public Image GetImageFromWebRoot(string name) {
  20.  
  21. // e.g.: imgPath = "D:\Hosting\ProjectFolder\wwwroot\beep.png"
  22. var imgPath = Path.Combine(_hostingEnvirounment.WebRootPath, name);
  23.  
  24. return Image.FromFile(imgPath);
  25. }
Add Comment
Please, Sign In to add comment