We're sorry GroupDocs doesn't work properply without JavaScript enabled.

Free Support Forum - groupdocs.com

How to create unique fileCacheSubFolder in .NET

How do we create unique fileCacheSubFolder?? In our case url can "DataFiles\EmpDocs\54808\ApplicationForms\teacher.docx for client A and “DataFiles\EmpDocs\54809\ApplicationForms\teacher.docx” for client B. As you have notice both file name exactly same. So it will create “teacher_docx” fileCacheSubFolder. So how can we create unique fileCacheSubFolder for each file which has different location?


This Topic is created by vladimir.litvinchik using Email to Topic tool.

@supahoops

You can use any path for the fileCacheSubFolder variable, so let’s take this two lines of code

var fileFolderName = Path.GetFileName(documentGuid).Replace(".", "_");
string fileCacheSubFolder = Path.Combine(cachePath, fileFolderName);

The first line is responsible for creating unique relative folder path e.g. teacher_docx for a file and the second one is responsible for combining base cache path with relative cache path e.g. .\cache\teacher_docx. You can build unique cache folder path by adding username or user ID e.g. .\cache\{userID or username}\teacher_docx. The final code will be something like this

var userId = GetUserId();
var fileFolderName = Path.GetFileName(documentGuid).Replace(".", "_");
string fileCacheSubFolder = Path.Combine(cachePath, userId, fileFolderName);

At this point, we know how to create a unique folder path per user and file but we don’t have a user. How do you plan to authenticate users in your app?