Click here to Skip to main content
14,826,492 members
Please Sign up or sign in to vote.
1.80/5 (3 votes)
See more:
Hi
Can we use App_Data folder to upload normal image or word files in
is there any security issues with this folder or it can be configured to use for upload and access folder.
Posted
Updated 29-Jan-21 3:31am

The App_Data folder is a special folder reserved for data such as database files and so on, and will NOT render out any contents on the web. This is by design, and intentional and cannot be changed.

It's better if you can create a folder (eg. uploads) inside the Content folder and use that for uploading your files.Then your users can access the content of that folder.

Check how can be done it :Unable to access images stored inside my App_Data folder
   
Hi yes, it is possible to display it from the App_Data Folder.
In order to display the image, you have to convert it to base64string.

<pre>
public string ReturnImage()
{


 string imageYouWantToDisplay = "Test.png";
 string base64String = "";
 String path = HostingEnvironment.MapPath("~/App_Data");

alternatively if you wanted to pass a param.

so for example

int WhatEverId = 5

 ~/App_Data/YourFolder/5/imageYouWantToDisplay

your path will then look like this.

String folderPath = HostingEnvironment.MapPath("~/App_Data/YourFolder") + @"\" + WhatEverId.ToString();

using (Image image = Image.FromFile(path + "/" + imageYouWantToDisplay))
      {
         using (MemoryStream m = new MemoryStream())
          {
            image.Save(m, image.RawFormat);
            byte[] imageBytes = m.ToArray();

            // Convert byte[] to Base64 String
              base64String = Convert.ToBase64String(imageBytes);
          }
        }
 return base64String;
}

you can then call that in an action method

public DisplayImages (){
 List<WhateverModel> test = new List<WhateverModel>();
 
test = GetAll().ToList();

test.ForEach(x=> { MyImage = ReturnImage();});

return test;

}

@model WhateverModel

<pre>    <img src="@MyImage" />


javascript

<pre>    <img src="${MyImage}" />
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900