0

I have a ASP.Net website and in some cases it's generating .pdf-files and .csv files for users to download.

Now my question: What is the default directory for saving that files on the webserver? Is there any ASP.NET Folder like App_... or something like that?

What can you recommend?

Nagelfar
  • 803
  • 2
  • 8
  • 21

5 Answers5

3

If you don't want to reuse the files, stream the files directly without saving it to disk.

If you save it to disk you have to ask yourself if the content of the file is to be available to all users or if it's a bad idea that other users can access the files. If it's a bad idea, the folder you put the files in should be made unavailable to the users by setting access rights correspondingly. You can either do this by putting the folder outside of the web site directory or by setting security settings in the file system or on the web server.

You can basically put the files in any folder that is made writable for the user writing the file (typically the ASP.NET App Pool user). IIRC the App_data folder is writable by default for the ASP.NET user, so that could be a candidate.

PHeiberg
  • 29,411
  • 6
  • 59
  • 81
  • Thanks for your answer! That thing with streaming files without saving to disc sounds really interesting to me! How can I do that? – Nagelfar Sep 20 '12 at 18:31
  • @Nagelfar - If you use MVC you can see [this question](http://stackoverflow.com/questions/5828315/write-pdf-stream-to-response-stream). If you use webforms see [here](http://stackoverflow.com/questions/5916647/write-pdf-stream-to-response-stream). Basically you can stream any type of stream (MemoryStream if you don't have a physical file) in the way illustrated by the linked examples. – PHeiberg Sep 20 '12 at 19:28
  • @Nagelfar - If you use a component for generating the PDF files in memory, there usually is a option for writing the file to a stream. For the same goes for CSV-file libraries. If you generate the CSV-files yourself, there is a [question here](http://stackoverflow.com/questions/946908/asp-net-stream-content-from-memory-and-not-from-file) about streaming CSV. – PHeiberg Sep 20 '12 at 19:58
1

You can create your proper folder for this need

Here list of specific Folder (But you don't need):

App_GlobalResources, 
App_LocalResources, 
App_Resources
App_Themes
App_WebReferences)
App_Code
App_Data
App_Browsers

Here MSDN link about project structure

Link : http://msdn.microsoft.com/en-us/library/ex526337%28v=vs.100%29.aspx

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
1

It's really up to you! I would recommend you put them in a sub folder of your solution so that they are self contained and you can easily control security without worrying about folders further down the tree.

Oliver Gray
  • 874
  • 6
  • 17
1

Folder is anything you tell it to be. If you have low volume you could just stream the files from memory so they're not stored on the server.

Neil Wood
  • 153
  • 2
  • 14
0

It is also important that you consider whether you are going to have more than one web server, and have servers in a cluster. To be ready for such a case, it is better not to keep the files under the web application folder, and not to access them relatively to the application path, but keep the files in a separate folder that you could easily expose (there will still be security issues) as a network path.

Ben
  • 398
  • 2
  • 8