Hi,
I tried 2 options,
- option 2 is working by appending Guidid but the file name format is not as per the expectation (mentioned in my initial post).
- option 1 is working only partially. lets assume the file samplefile.pdf already exists. when i upload the another file with same name samplefile.pdf , then per the code it is named as samplefile(1).pdf But again if i upload another file with same name samplefile.pdf, the issue here is it is replacing the previously samplefile(1).pdf named file to same name i.e. samplefile(1).pdf. Expectation in this scenario is to name the file as samplefile(2).pdf
Need inputs to achieve the solution.
- OPTION 1:
int i = 0; string fileName = string.Empty; DownloadFileResponse PdfResponse = await _blobManager.DownloadPdfFileAsync("workflow-queue", request.FormFile.FileName, cancellationToken).ConfigureAwait(false); if (PdfResponse.IsExist) { // option 1 if (i == 0) fileName = request.FormFile.FileName.Replace(".pdf", "(" + ++i + ")" + ".pdf"); else fileName = request.FormFile.FileName.Replace("(" + i + ")" + ".pdf", "(" + ++i + ")" + ".pdf"); await _blobManager.UploadFileAsync("workflow-queue", fileName, request.FormFile.ToBytes(), cancellationToken).ConfigureAwait(false); } else { await _blobManager.UploadFileAsync("workflow-queue", request.FormFile.FileName, request.FormFile.ToBytes(), cancellationToken).ConfigureAwait(false); }
- OPTION 2:
int i = 0; string fileName = string.Empty; DownloadFileResponse PdfResponse = await _blobManager.DownloadPdfFileAsync("workflow-queue", request.FormFile.FileName, cancellationToken).ConfigureAwait(false); if (PdfResponse.IsExist) { // option 2 fileName = request.FormFile.FileName.Replace(".pdf", "-" + Guid.NewGuid().ToString() + ".pdf"); await _blobManager.UploadFileAsync("workflow-queue", fileName, request.FormFile.ToBytes(), cancellationToken).ConfigureAwait(false); } else { await _blobManager.UploadFileAsync("workflow-queue", request.FormFile.FileName, request.FormFile.ToBytes(), cancellationToken).ConfigureAwait(false); }
Thankyou.