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 20 posts 90 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 Lopez 168 posts 958 karma points MVP 4x c-trib
    May 31, 2019 @ 04:08
    Mario Lopez
    100

    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);
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft