Search code examples
c#.netasp.net-coreazure-appservice

Can'not able to edit a file after publish my .net core API to azure app service


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.enter image description here

Is it permission related problem ? How can i solve it . this in My sample code .

 var localRdlcFilePath = Path.Combine(Path.GetTempPath(), "prescription.rdl");  
     QRCodeGeneratorHelper.DownloadRdlcFileFromAzureStorage(connectionString, containerName, blobName, localRdlcFilePath);

May be above line make the problem.

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;
            }

Solution

  • In this situation I used Basic B1 windows package used for test app. That's why I can't able to edit any file programatically.

    Now, I purchase a package for Production and deploy my app to azure app service Now my programme is working successfully.