Uploading files to Personal Website

Jctech2025 5 Reputation points

Hi All, I don't believe I have posted to this forum.

So here's my issue. Running my own website in IIS on Windows 10. The site runs fine I can connect to it from anywhere using my ddnsname:port number. So I'm trying to make the feature where I can upload a file to the site from whatever devices I'm connected from. Here my code without giving away too much:

<form action="http://siteaddres:portnumber/Uploadfolder" method="POST" enctype="multipart/form-data"> <label style="color: white" for="myfile">Choose File to Upload:</label> <input type="file" id="myfile" name="filename"> <button type="submit">Upload</button>

Problem is every time I select the file from the machine I'm on and hit upload, it tells me the destination is either moved or unavailable. I am new to this. I'm sure I'm missing something. Thoughts? Thanks.

0 comments No comments

Sign in to comment

2 answers

  1. AI answer

    The HTML form alone is not enough to upload a file to a folder in IIS. A server-side component must receive the POST, read the uploaded file, and save it to a physical path on disk.

    Key points:

    1. The form’s action should point to a server-side handler (for example, an ASP.NET page), not directly to a folder:
       <form action="http://siteaddress:portnumber/Upload.aspx" method="POST" enctype="multipart/form-data">
       <label style="color: white" for="myfile">Choose File to Upload:</label>
       <input type="file" id="myfile" name="myfile" />
       <button type="submit">Upload</button>
       </form>
      
    2. In the ASP.NET handler (for example, Upload.aspx.cs), use the file upload control to save the file to a folder on the server. The folder must exist and the IIS application pool identity must have write permissions to it. Example using a FileUpload control on an ASP.NET Web Form:
       using System;
       using System.IO;
       
       public partial class Upload : System.Web.UI.Page
       {
       protected void UploadButton_Click(object sender, EventArgs e)
       {
       if (FileUpload1.HasFile)
       {
       string fileName = Path.GetFileName(FileUpload1.FileName);
       string virtualPath = "~/Uploadfolder/" + fileName;
       string physicalPath = Server.MapPath(virtualPath);
       
       FileUpload1.SaveAs(physicalPath);
       }
       }
       }
      
      Server.MapPath converts the virtual path (like ~/Uploadfolder/fileName) to the physical path on disk (for example, C:\Websites\YourSite\Uploadfolder\fileName). SaveAs then writes the file there.
    3. If using Razor Web Pages, read the uploaded file from Request.Files and save it using Path.GetFileName to strip the client path, then write it into a folder (for example, UploadedFiles) that exists under the site and is writable.
    4. The error “destination is either moved or unavailable” typically occurs because:
      • The form posts directly to a folder URL that IIS does not handle as an upload endpoint.
      • The target folder does not exist.
      • IIS does not allow writing to that location or the app pool identity lacks NTFS write permissions.

    Configure a proper upload handler (ASP.NET page or similar), ensure the upload folder exists under the site, and grant write permissions to the IIS application pool identity. Then point the form’s action to that handler instead of the folder.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.
  2. Brian Huynh 3,305 Reputation points Microsoft External Staff Moderator

    Hello Jctech2025, thank you for posting in the Microsoft Q&A community.

    This behavior is completely expected based on your current HTML code. The issue is occurring because your form's action attribute is pointing directly to a folder directory (http://siteaddres:portnumber/Uploadfolder). By default, IIS does not know how to handle an HTTP POST request sent directly to a physical or virtual folder. An HTML form simply packages the file and sends it over the network, but IIS requires a server-side application (such as ASP.NET, PHP, Python, etc.) to actively receive that package, parse it, and write it to your hard drive.

     To resolve this, we need to introduce a server-side handler to receive the POST request and ensure your IIS permissions are correctly configured to allow saving the file.

    First, update your HTML form so the action points to a server-side script endpoint instead of a folder.

    Next, you will need to create the Upload.aspx script in your website's root directory to process the upload. Here is an ASP.NET C# example that receives the file and securely saves it into upload folder: 

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.IO" %>
    
     
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Files.Count > 0)
            {
                try
                {
                    var file = Request.Files[0];
                    if (file != null && file.ContentLength > 0)
                    {
                        string fileName = Path.GetFileName(file.FileName);
                        // Map the virtual path to the physical disk path
                        string savePath = Server.MapPath("~/Uploadfolder/") + fileName;
                        file.SaveAs(savePath);
                        Response.Write("File uploaded successfully.");
                    }
                }
                catch (Exception ex)
                {
                    Response.Write("Error: " + ex.Message);
                }
            }
        }
    </script>
    
    

    As a final step, IIS needs permission to write to your destination folder. By default, IIS runs websites under an application pool identity that only has "Read" access to protect your system.

    • Open File Explorer and navigate to the physical path of your website.
    • Right-click your Uploadfolder, select Properties, and go to the Security tab.
    • Click Edit, then click Add.
    • Type IIS_IUSRS in the object names box. 
    • Click Check Names and then click OK.
    • Select the newly added IIS_IUSRS group from the list, and check the Modify box under the Allow column. 
    • Click Apply and OK.

    If you are using a different web framework (like PHP or Node.js) instead of ASP.NET, please let me know your specific environment. Alternatively, to help us isolate the issue further, please check your IIS Logs located at %SystemDrive%\inetpub\logs\LogFiles and share the exact HTTP status code (e.g., 405 Method Not Allowed) generated when you click Upload.

    I will follow up on this thread to ensure your issue is resolved. If the guidance provided helped you navigate to this solution, please consider clicking 'Accept answer'. This officially marks the thread as answered and greatly helps other community members who are searching for a solution to this exact same problem.

    1. Jctech2025 5 Reputation points

      Hi Brian, Thanks for the response. My forms attribute, I wrote it that way based on feedback from other forums. The function does not currently work at the moment anyway. So currently I am just running IIS on Windows. My site works and I am able to connect to it via offsite from where my machine sits.

      Am I able to make this work based on that and without adding another machine into the picture?

      Thanks,

    2. Jctech2025 5 Reputation points

      Hi Brian, Thanks for the response. My forms attribute, I wrote it that way based on feedback from other forums. The function does not currently work at the moment anyway. So currently I am just running IIS on Windows. My site works and I am able to connect to it via offsite from where my machine sits.

      Am I able to make this work based on that and without adding another machine into the picture?

      Thanks,

    3. Jctech2025 5 Reputation points

      Hi Brian, also I'm not running my website from the default location on the C: drive. I'm running it from a connected usb drive.

      The asp.net script, does that have to be made using something like visual studio?

      In this part string savePath = Server.MapPath("~/Uploadfolder/") + fileName;, do I replace Uploadfolder, to be the specific physical path of the folder?

      In the thread it says "http://siteaddress:portnumber/Upload.aspx", is this going to be my isp ip or would I put my dnshostname?

      Again I am new to this and trying to make this work, partly for my own learning. Obviously I have things to change here, thanks for the feedback.

    4. Brian Huynh 3,305 Reputation points Microsoft External Staff Moderator

      Hi Jctech2025, thank you for the follow-up and for sharing more details!

      To answer your questions directly:

      1. Do I need another machine? You absolutely do not need another machine. Your current machine running IIS is capable of handling this. The only thing missing is a set of instructions (ASP.NET) that tells IIS how to process the file you are uploading.

      2. Do I need Visual Studio to make the ASP.NET script? No, you do not need Visual Studio. You can create this file using the standard Notepad built into Windows.

      • Simply open Notepad.
      • Paste the C# code from my previous response.
      • Click File > Save As.
      • Change the "Save as type" dropdown to All Files (.).
      • Name the file Upload.aspx and save it directly into the main folder of your website on your USB drive.

      3. What address should I put in the HTML form? ISP IP or DNS Hostname? The best practice is to use a relative path. This means you don't need to put your IP address or hostname at all. Because your HTML file and your Upload.aspx file will live in the exact same folder on your website, you can simply write it like this:

      <form action="Upload.aspx" method="POST" enctype="multipart/form-data">
      

      By doing this, the form automatically knows to look for Upload.aspx on whatever IP or Hostname the user is currently connected to.

      4. How does the savePath work with a USB drive? The command Server.MapPath("~/Uploadfolder/") is a dynamic helper. The ~ symbol represents the root directory of your website. If you pointed your IIS website to a folder on your USB drive (for example, E:\MyWebsite\), IIS automatically translates ~/Uploadfolder/ into E:\MyWebsite\Uploadfolder\.

      So, as long as you have a folder literally named Uploadfolder inside your website's main folder on the USB drive, you do not need to change that line of code. It will find the physical path automatically.

      Next Step: Enable ASP.NET on your machine Because you are running IIS on a standard Windows 10 machine, it might not have the ASP.NET feature turned on by default. To make the script work, you must enable it first:

      1. Press the Windows Key + R to open the Run dialog.
      2. Type appwiz.cpl and press Enter.
      3. On the left side of the window, click Turn Windows features on or off.
      4. Expand Internet Information Services > World Wide Web Services > Application Development Features.
      5. Check the box for ASP.NET 4.8 (or ASP.NET 3.5 / 4.x, depending on what is listed for your version of Windows).
      6. Click OK and let Windows install the required components.

      A Quick Note on USB Drive Permissions: Because your site is on a USB drive, please ensure the drive is formatted as NTFS so you can apply the folder permissions. You will still need to right-click the Uploadfolder on your USB drive, go to the Security tab, and grant Modify permissions to the IIS_IUSRS group as mentioned in the first response. If IIS does not have permission to write to that USB folder, you will receive an "Access Denied" error when trying to upload.

      Take your time setting this up, and please let me know how it goes! I will continue to follow up on this thread.

    5. Jctech2025 5 Reputation points

      Hi Brian,

      Just now reading your update. Thank you! I'll reference what you provided and update back as soon as possible.


    Sign in to comment
Sign in to answer

Your answer