Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Christian Koch 14 posts 84 karma points
    May 31, 2019 @ 01:07
    Christian Koch
    0

    Access files in Media Folder

    I try to pass a JSON file to a variable in a partial view. The JSON-File is stored in Media-Folder.

    I got a 401 if I use the full url.

    var json = webClient.DownloadString(@"https://yourdomain.com/media/laghsvgk/json.json");
    

    What is the reason?

    How can I render the pysical path (like c:\home\site\wwwroot\media\laghsvgk\json.json) of the media file?

  • Mario 140 posts 836 karma points c-trib
    May 31, 2019 @ 04:08
    Mario
    0

    Hi Christian,

    I guess you have the json file in your own server and not in a external site?

    If that's the case you should use something like this instead:

    using (StreamReader r = new StreamReader(Server.MapPath("~/media/laghsvgk/json.json")))
    {
         string json = r.ReadToEnd();
    
         //then cast it to your model or whatever.
         List<Item> items = JsonConvert.DeserializeObject<List<Item>>(json);
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies