I'm unable to edit file using C# code .Net 5 inside wwroot folder in azure app service. Is it possible to Edit file Inside wwroot folder using C# code .Net.
Not .rld only any file in wwroot folder .net core app. I'm able to edit it when I run my .net core app locally even it works when i publish it to another server . but after publish azure app service it can't able to edit the text file .
It shows 500 error.
QRCodeGeneratorHelper.DownloadRdlcFileFromAzureStorage Code :
public static void DownloadRdlcFileFromAzureStorage(string connectionString, string containerName, string blobName, string localFilePath)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(containerName);
CloudBlockBlob blob = container.GetBlockBlobReference(blobName);
using (var fileStream = File.OpenWrite(localFilePath))
{
blob.DownloadToStreamAsync(fileStream).Wait();
}
}
Full Code :
try
{
int extension = 1;
string mimtype = $"";
var prescription = await _prescriptionRepo.GetPriscriptionById(id);
//Azure Blob
string connectionString = "connectionstringhere";
string containerName = "namehere";
string blobName = "report/prescription.rdl";
var localRdlcFilePath = Path.Combine(Path.GetTempPath(), "prescription.rdl");
QRCodeGeneratorHelper.DownloadRdlcFileFromAzureStorage(connectionString, containerName, blobName, localRdlcFilePath);
List<ImageStorage> datasrc2 = new()
{
new ImageStorage() {Id=1,Image = GenerateQrCode("http://www.outreachforall.org/")},
};
// End Of QR code
var pres = _mapper.Map<GetPrescriptionForReport>(prescription);
Dictionary<string, string> parameter = new Dictionary<string, string>
{
{ "patientname", $"{prescription.Patient.FirstName} {prescription.Patient.LastName}" },
{ "prescriptionid", $"{prescription.PatientId}" },
{ "advice", $"{prescription.Note}" },
{ "doctorname", $"{prescription.DoctorFirstName} {prescription.DoctorLastName}" },
//{"image", imagae}
};
LocalReport localReport = new LocalReport(localRdlcFilePath);
localReport.AddDataSource("DataSet1", pres.MedicineForPrescription);
localReport.AddDataSource("DataSet2", datasrc2);
var result = localReport.Execute(RenderType.Pdf, extension, parameter, mimtype);
var foo = File(result.MainStream, "application/pdf");
foo.FileDownloadName = $"{prescription.PatientId}-{prescription.Patient.FirstName} {prescription.Patient.LastName}.pdf";
return foo;
}
catch (Exception ex)
{
// Log or handle the exception appropriately
throw;
}
Detailed Question Bellow Link.
https://stackoverflow.com/questions/77414664/cannot-able-to-edit-a-file-after-publish-my-net-core-api-to-azure-app-service