Can'not able to modify a file after publish my .net core API to azure app service FronEnd I'm Using Angular

Mehdi Hasan 0 Reputation points
2023-11-05T08:13:24.25+00:00

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.

azure

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

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,860 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,560 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,778 questions
{count} votes

1 answer

Sort by: Most helpful
  1. VenkateshDodda-MSFT 20,781 Reputation points Microsoft Employee
    2023-11-06T10:04:50.19+00:00

    @Mehdi Hasan Thanks for reaching out to Microsoft Q&A, apologize for any inconvenience caused on this.

    Based on the shared information, I understand that you want to know How to edit the files that were present under the wwwroot folder of your app service. Correct me if my understanding in wrong.

    Irrespective of operating system it is hosted either in Windows based or Linux based app service plan. By default, you can edit the contents inside wwwroot folder using Advanced Tools (Kudu console).

    You can access the Kudu console by requesting to this URL https://<app-name>.scm.azurewebsites.net in the browser.

    • If your app is running windows based app service plan, then you will have either CMD\Powershell to edit or update the files in the app service file system.
    • If your app is running in Linux based plan then you can use either SSH\Bash to edit or update the files.

    Refer to this documentation to know more information about KUDU console.

    Alternatively, you can also use App service editor(provides in-browser-editing experience of your app code) which is available in windows-based app service plans as shown below.

    User's image

    Feel free to reach back to me if you have any further questions on this.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.