Click here to Skip to main content
15,437,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys how can i upload image to my network folder i this is my code

HRIS.cshtml
<pre> <div class="pb-2 shadow" style="background-color: gray;  height: 150px; width: 150px ; position:relative; align-self:center" id="employee-pic-preview">
                        <img src="#" alt="Employee Pic" style="height:inherit;width:inherit" id="employeepic" />

                    </div>
                    
                        <div class="pb-2 justify-content-center align-content-center" style=" width: 100%" id="upload-button">
                            <div class="input-group mb-3 " style=" display:inline-flex !important;">
                                <div class="custom-file bg-white border rounded" style="height:inherit">
                                    <label class="label text-black-50 text-left font-weight-bold text-center" for="inputGroupFile02">Browse Photo</label>
                                    <input type="file" class="custom-file-input" id="inputGroupFile02">
                                    @*<label class="custom-file-label" for="inputGroupFile02" aria-describedby="inputGroupFileAddon02">Choose file</label>*@
                                </div>
                            </div>
                        </div>



And this is my ModulesController
<pre> [HttpPost]
        public JsonResult uploadFile(HttpPostedFileBase employeepic)
        {
            if (employeepic != null)
            {
                /*  //rezie image before saving to network folder
                  using var image = Image.Load(employeepic.OpenReadStream());
                  image.Mutate(x => x.Resize(150, 150));
                  image.Save(employeepic.FileName); */

                string path = @"\\13.10.10.12\AQSImages\IdPictures\";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                employeepic.SaveAs(path + Path.GetFileName(employeepic.FileName));
            }

            return Json("Successfully added photo!");
        }


What I have tried:

I tried so many in youtube but not working!
Posted
Updated 13-Jun-22 5:23am

1 solution

By default, your ASP.NET app runs under a service account. That account does not have permissions to access network resources, like your server share.

You have to run your app under a user account specifically setup for access to that share. Create a user account and give it permissions to the share, then go into IIS and the Application Pool that your ASP.NET app is running under. Change the account information to the account you created and restart the pool.
 
Share this answer
 
Comments
Ramon Ortega Jr 13-Jun-22 14:02pm    
YES BRO I HAVE ACCESS TO THE NETWORK FOLDER
Dave Kreskowiak 13-Jun-22 14:13pm     CRLF
I am not your "bro". YOUR account has access to the network share, but the account running your website on your web server does not.

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



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