0

How to record files on a server with minimal access using MVC. The next version of the code is not suitable as it will be clogging up the domain.

Controller code:

var fileFile = Request.Files["p" + prop.Id];
if (fileFile == null) continue;

string pathFile = AppDomain.CurrentDomain.BaseDirectory + "UploadedFiles";
string filenameFile = Path.GetFileName(fileFile.FileName);

if (filenameFile != null) fileFile.SaveAs(Path.Combine(pathFile, filenameFile));

(if it is possible to realize this by putting file to the cache)

EDITED CODE:

var ordinaryPropertyValue = new Catalog.Core.Entities.OrdinaryPropertyValue();

Environment.CurrentDirectory = Environment.GetEnvironmentVariable("TEMP");

var fileFile = Request.Files["File" + prop.Id]; if (fileFile == null) continue;

string pathFile = Environment.CurrentDirectory;

fileFile.SaveAs(pathFile);

ordinaryPropertyValue.Value = pathFile;

instance.SetPropertyValue(prop.Id, ordinaryPropertyValue);

revolutionkpi
  • 2,632
  • 10
  • 45
  • 84

1 Answers1

1

You could use the common application data location (this would be better than %TEMP% if you need them to stick around - people have a tendency to clean the %TEMP% folder out from time to time in my experience) - all users should have access to that and then you could just put it in a sub-folder like so:

var appDataFolder = System.Environment.GetFolderPath(SpecialFolder.CommonApplicationData);
var dir = Path.Combine(Path.Combine(appDataFolder, "My Application"), "UploadedFiles"):

// save your files into dir

Here are all the "special folders" in case you see one that you would rather use: Environment.SpecialFolder

kmp
  • 10,535
  • 11
  • 75
  • 125