locked
file download from share but folder has spaces RRS feed

  • Question

  • User518677258 posted

    There must be a better way - 

    My webpage has an anchor <td><a href=@item.ArchivePath>DownLoad:@item.ArchivePath</a></td>

    The path is to a share like \\MyVirtServer\Archives\   - some of the next folders  have a space  as in  "My folder" , some do not. lets call it ATpath

    I build the archive path in the Index.cshtm.cs 

    thePath = ROOTARCHIVE + ATpath +"\\

    I have tried  both  string escapedFolderPath= Uri.EscapeUriString(ATpath);
    escapedFolderPath = HttpUtility.UrlEncode(ATpath);  Everything works fine except on the folders with spaces 

    If I don't do anything the href  breaks at \\MyVirtServer\Archives\My   - so no good

    with   HttpUtility.UrlEncode(ATpath); I get what appears to be a  file:  \\MyVirtServer\Archives\ My+Path\ .... that's also no good

    with Uri.EscapeUriString(ATpath);  I get what appears to be a  file:  \\MyVirtServer\Archives\ My%20Path\ .... that's also no good

    If I just remove the %20 or the + in the address bar I can download the file.   I could try and clean this mess up with Jscript, but surely there is must a more direct solution

    Thanks ! 

    Saturday, April 20, 2019 1:43 AM

Answers

  • User-893317190 posted

    Hi andrewcw,

    I have tried your code and find only need to wrap  your address with " , space will not cause problem.

    Below is my code.

     public ActionResult About()
            {
                Item item = new Item()
                {
                    ArchivePath = @"\\MyVirtServer\Archives\My Folder"
                };
                ViewBag.Message = "Your application description page.";
    
                return View(item);
            }
    
    
        public class Item
        {
            public string ArchivePath { get; set; }
        }
    <a href="@Model.ArchivePath">DownLoad:@Model.ArchivePath</a>

    The result.

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 22, 2019 2:50 AM

All replies

  • User-893317190 posted

    Hi andrewcw,

    I have tried your code and find only need to wrap  your address with " , space will not cause problem.

    Below is my code.

     public ActionResult About()
            {
                Item item = new Item()
                {
                    ArchivePath = @"\\MyVirtServer\Archives\My Folder"
                };
                ViewBag.Message = "Your application description page.";
    
                return View(item);
            }
    
    
        public class Item
        {
            public string ArchivePath { get; set; }
        }
    <a href="@Model.ArchivePath">DownLoad:@Model.ArchivePath</a>

    The result.

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 22, 2019 2:50 AM
  • User518677258 posted

    Thanks !!!!

    Monday, April 22, 2019 3:31 PM