Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

from debug it have value

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 exception error 

so why this error display ?


What I have tried:

PathDirectory = "\\\\10.253.x.xx\\ImportExport\\testImporter\\3"
 string PathDirectory = myValue1 + "\\" + Month;
 if (!Directory.Exists(PathDirectory))
                 {
    
                     Directory.CreateDirectory(PathDirectory);
    
                 }
Posted
Updated 30-Mar-22 13:54pm

The account your web API is running under does not have access to the network share. Really, it shouldn't at all since you're giving a service account that can be compromised by malicious code access to resources other than the folder the website is running from.

To fix this, create a user account specifically for running your website. Change the Application Pool running your site to use this account, then give the account permissions to the share, and appropriate NTFS permissions to the folder you shared. In your case, that would be the ImportExport share on your server.

*** WARNING *** THIS IS A SECURITY RISK!
 
Share this answer
 
"10.253.x.xx" is not a valid IP address - all digit groups must be numeric, not alphabetic.
The software you are using to create the folder manually, is replacing it with a specific device IP at a guess.
 
Share this answer
 
Comments
ahmed_sa 30-Mar-22 18:38pm    
sorry i know that
but i can't share public ip
so this is not issue

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900