system.IO.Directorynotfoundexception for the file that exists in the network drive

Anjali Agarwal 1,611 Reputation points
2024-12-20T00:48:37.7066667+00:00

I am trying to open and fill a blank .pdf file. This blank .pdf file resides on the network drive. The path to that blank .pdf file is specified in the program.cs file. When I tried to read the blank .pdf file in my code, my code automatically goes to C:\ drive to read that blank .pdf file rather than the network drive. This is what I have in my code:

I have the following code in my program.cs file:

app.UseStaticFiles();
var configValue = builder.Configuration["ConfDestinationPath"];
var blankPDF = builder.Configuration["BlankPDFConfig"];
app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(configValue),
    RequestPath = "/testForm" // URL path
});
app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(blankPDF),
    RequestPath = "/BlankPDFForm" ,
    // URL path
});

this is what I have in my my appsettings.json file:

"ConfDestinationPath": "\\\\tcs-trs\\shared\\2024\\LanguageForms\\",
"BlankPDFConfig": "\\\\tcs-trs\\shared\\2024\\LanguageForms\\BlankPDFForm\\"

I have the following code in the controller:

string filledPDF = "/testForm/";
string blankPDF = "/BlankPDFForm/"; 
blankPDF = blankPDF + "TestForm.pdf";

Here, when I am trying to read pdf file, TestForm.pdf that resides in the network path, I get an error saying system.IO.Directorynotfoundexception and it looks for the TestForm.pdf file on C:\ drive rather than on this network drive:

\\tcs-trs\shared\2024\LanguageForms\BlankPDFForm\
using (PdfDocument pdf = new PdfDocument(blankPDF)) // I get an error here
{
}

Below is the screen shot of the error:

User's image

I am not sure why code is looking for that balnak pdf file on C:\drive when the file actaully resides on the network drive. I am not sure what am I doing wrong. I specified the network path fully in the program.cs file.

Any help will be apprecaited.

Developer technologies | .NET | Other
Developer technologies | ASP.NET Core | Other
0 comments No comments

1 answer

Sort by: Oldest
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

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