System.IO.IOException: 'The network path was not found : '\\10.253.x.xx\ImportExport\testImporter\3'' ?

ahmed salah 3,216 Reputation points
2022-03-30T14:41:36.857+00:00

I work on csharp application when i make shared path and create directory in it it tell me

The network path was not found

so why this issue display

although i can create folder 3 on this path \10.253.x.xx\ImportExport\testImporter\

but i can't create it from code

code i use it as below

var Pathdirectory=

from debug it have value

PathDirectory = "\\\\10.253.x.xx\\ImportExport\\testImporter\\3"
string PathDirectory = myValue1 + "\\" + Month;
if (!Directory.Exists(PathDirectory))
                {

                    Directory.CreateDirectory(PathDirectory);

                }

exception details

at System.IO.FileSystem.CreateDirectory(String fullPath)
at System.IO.Directory.CreateDirectory(String path)
at Framework.WebApi.Controllers.ZDataDelivery.Z2DeliveryController.Upload() in D:\moved\TestInternalSystemZ2Data\FullProjectAngApiLastUpdate\Z2DataApp\Framework.WebApi\Controllers\ZDataDelivery\Z2DeliveryController.cs:line 123
at lambda_method(Closure , Object , Object[] )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()

i can access path above and create folder 3 on it manually

but from code it give me path was not found on network

so why this error display ?

Developer technologies Transact-SQL
SQL Server Other
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2022-03-30T15:41:41.743+00:00

    This is a UNC path which means share security is involved. If you are using a UNC path in your app then the user who is running your app must have read/write permissions to that share in order for you to create a folder within it.

    Now looking at your callstack this is a web app. A web app generally runs in a sandbox and doesn't have permission to anything outside its own app directory. If your app needs to be able to write to other directories then you'll need to ensure that the app pool identity that the app is configured to use has write permissions to that UNC path. My guess is that they do not. Note that YOUR identity is not the identity that the web app runs under. So the fact that you can create the folder doesn't really help here because your user account isn't what is trying to do it. Given the specific error you're getting the web app does not have read access to the UNC share and therefore it is failing the call.

    You can fix this a couple of different ways. As a test change your app pool to run under your local user account. If it works then it is a permissions issue. Now change the app pool to run under a different user account that has network access and can read/write the UNC share. Then your problem should go away.

    1 person found this answer helpful.
    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.