AR.
AR.

Reputation: 40545

Where should I save files dynamically generated by the ASP.NET Web API?

My ASP.NET Web API service dynamically generates files for users to download.

The remote application sends a request to the API which:

  1. Generates the file and saves it ----> where?? <-----
  2. Returns the URL of the file location so it can be downloaded.

Nothing fancy there, but my question is what are the best practices for where to save these files? Some digging around suggests that App_Data might be the appropriate place but I haven't seen anything definitive.

Some considerations:

Thanks!

Upvotes: 3

Views: 3339

Answers (2)

Brett
Brett

Reputation: 4269

If you have access to your web server, you could also create a virtual directory under your web application and configure it to point to whatever file location you want. Then you can have your application save the files into that virtual directory using System.IO. That's what I've done in the past.

Upvotes: 1

Dai
Dai

Reputation: 155250

You can write to any location your application stores data in.

I recommend using the system Temp directory, that's what it's there for (System.IO.Path.GetTempPath()) or if your have write access, a subdirectory of your application:

String path = Server.MapPath("~/Temp");
if( !Directory.Exists( path ) ) Directory.CreateDirectory( path );

using(FileStream fs = File.OpenWrite( Path.Combine( path, "TempFileName.dat" ) )) {
    fs.Write( new Byte[1024] );
}

Upvotes: 4

Related Questions