Answer the question
In order to leave comments, you need to log in
ASP.NET How to properly organize work with files?
I am writing an application that uploads files to the server, performs some actions on them and sends them back to the user. After sending the files from the server must be deleted. It is necessary that every user who uploaded a document, whether anonymous or registered, get his own back. How, after all, is it right to organize the loading, storage, and naming of files in order to avoid conflicts?
PS While the primitive loading of the document through the form in the folder of the server is carried out.
Answer the question
In order to leave comments, you need to log in
to avoid conflicts?
---
Unique file name!?
...
try
{
// Get parameters
int chunks = context.Request["chunks"] != null ? int.Parse(context.Request["chunks"]) : 1;
int chunk = context.Request["chunk"] != null ? int.Parse(context.Request["chunk"]) : 0;
string photoTempName = context.Request["name"] ?? string.Empty; //это уникальноеимя для файла
...
public string GenerateFileName(string context)
{
return context + "_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + Guid.NewGuid().ToString("N");
}
filename1 = GenerateFileName("MeasurementData");
filename2 = GenerateFileName("Image");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question