Virtual directory not included in the image's urls

4 years ago
Hi,

If am running nopCommerce under the IIS virtual directory (for example shop.com/nopcommerce/) the images inserted from the Roxy Fileman into the WYSIWYG editor do not contain the virtual directory which results into 404 of course.

The same issue reported here: https://www.nopcommerce.com/boards/t/32133/solved-upload-with-roxy-fileman.aspx#135998.

Thanks
4 years ago
Hi,

Thanks for reporting. This is a known issue - https://github.com/nopSolutions/nopCommerce/issues/142. It's already stated in the \Administration\Views\Shared\EditorTemplates\RichEditor.cshtml file
3 years ago
Hi, Do we have any update on the same, using nopCommerce 3.40?
3 years ago
No. This work item is still open
3 years ago
recently I have to work with this issue and following fixes it with Roxyfileman:
this is how i did it though can be refactored:

Webconfig:  <add key="ImageVirtualDirectory" value="D:/temp/vdirs"/>
it works differently if on network:
<add key="ImageVirtualDirectory" value="////Nasserv01/shared/test"/>

conf.json:
    "FILES_ROOT": "~/Content/Images/uploaded", // set it to your virtual image directory


RoxyFilemanController

        private string confFile = "~/Content/Roxy_Fileman/conf.json"; // if IIS has an issue with json otherwise not needed
        private string rootDirectory = "~/content/images/uploaded";


        private static readonly string ImageVirtualDirectory = ConfigurationManager.AppSettings["ImageVirtualDirectory"];
        private const string ImageVirtualDirectoryName = "Content"; // or whatever

   private string FixPath(string path)
        {
            if (path == null)
                path = "";

            if (!path.StartsWith("~"))
            {
                if (!path.StartsWith("/"))
                    path = "/" + path;
                path = "~" + path;
            }
            path = path.Replace("\\", "/");
            if (!string.IsNullOrEmpty(ImageVirtualDirectory) && path.Contains(ImageVirtualDirectory))
            {
                path = path.Replace(ImageVirtualDirectory, ImageVirtualDirectoryName);
            }
            if (!path.ToLowerInvariant().Contains(rootDirectory))
                path = rootDirectory;
            return _context.Server.MapPath(path);
        }

        protected void ListDirTree(string type)
        {
            DirectoryInfo d = new DirectoryInfo(GetFilesRoot());
            if (!d.Exists)
                throw new Exception("Invalid files root directory. Check your configuration.");

            ArrayList dirs = ListDirs(d.FullName);
            dirs.Insert(0, d.FullName);

            string localPath = _context.Server.MapPath("~/");
            _r.Write("[");
            for (int i = 0; i < dirs.Count; i++)
            {
                string dir = (string)dirs[i];
                _r.Write("{\"p\":\"/" + dir.Replace(localPath, "").Replace("\\", "/").Replace(ImageVirtualDirectory, "Content") + "\",\"f\":\"" + GetFiles(dir, type).Count.ToString() + "\",\"d\":\"" + Directory.GetDirectories(dir).Length.ToString() + "\"}");
                if (i < dirs.Count - 1)
                    _r.Write(",");
            }
            _r.Write("]");
        }


protected void ListFiles(string path, string type)
        {
            CheckPath(path);
            string fullPath = FixPath(path);
            List<string> files = GetFiles(fullPath, type);
            _r.Write("[");
            var virtualPath = fullPath.Replace("\\", "/");
            if (virtualPath.Contains(ImageVirtualDirectory))
            {
                path = virtualPath.Replace(ImageVirtualDirectory, "/Content");
            }
// remaining code



// for network virtual path
private string FixPath(string path)
  {

      if (!path.StartsWith("~")){
      if (!path.StartsWith("/"))
        path = "/" + path;
      path = "~" + path;
    }

        path = path.Replace("\\", "/");
        if (!string.IsNullOrEmpty(ImageVirtualDirectory) && path.Contains(ImageVirtualDirectory))
        {
            path = path.Replace(ImageVirtualDirectory, ImageVirtualDirectoryName);
        }
        if (!path.ToLowerInvariant().Contains(rootDirectory))
            path = rootDirectory;
                
    return _context.Server.MapPath(path);
  }

  protected void ListDirTree(string type)
  {
    DirectoryInfo d = new DirectoryInfo(GetFilesRoot());
    if(!d.Exists)
      throw new Exception("Invalid files root directory. Check your configuration.");

    ArrayList dirs = ListDirs(d.FullName);
    dirs.Insert(0, d.FullName);

    string localPath = _context.Server.MapPath("~/");
    _r.Write("[");
    for(int i = 0; i <dirs.Count; i++){
      string dir = (string) dirs[i];

        var newPath = "{\"p\":\"/" +
                      dir.Replace(localPath, "").Replace("\\", "/") +
                      "\",\"f\":\"" + GetFiles(dir, type).Count.ToString() + "\",\"d\":\"" +
                      Directory.GetDirectories(dir).Length.ToString() + "\"}";
        newPath = newPath.Replace("///", "////").Replace(ImageVirtualDirectory, "/Content/files");
            _r.Write(newPath);
      if(i < dirs.Count -1)
        _r.Write(",");
    }
    _r.Write("]");
  }

  protected void ListFiles(string path, string type)
  {
    CheckPath(path);
    string fullPath = FixPath(path);
    List<string> files = GetFiles(fullPath, type);
    _r.Write("[");


        var virtualPath = fullPath.Replace("\\", "/");
        if (virtualPath.Contains(ImageVirtualDirectory))
        {
            path = virtualPath.Replace(ImageVirtualDirectory, "/Content/files");
        }
3 years ago
[quote=asn]...this is how i did it though can be refactored.../quote]
Thanks a lot for this conribution! We'll check it
2 years ago
Hi. Was it fixed in any version?
2 years ago
And finally we have added support for virtual directories in the the RoxyFileman. This will be in the new 4.0 version. You can see the changes here, here, here and maybe somewhere else