Click here to Skip to main content
15,877,051 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

<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 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>*@

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 = @"\\\AQSImages\IdPictures\";
                if (!Directory.Exists(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!
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
Ramon Ortega Jr 13-Jun-22 14:02pm    
Dave Kreskowiak 13-Jun-22 14:13pm    
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