Upload file

Vote:
 

Hi,

We can upload files in the previous version programaticaly and using specific provider.

How can we do the same thing in the latest CMS?

EPiServer 8 implementation:

        public string UploadFile(HttpPostedFileBase file, string providerName)
        {
            if (file == null || file.ContentLength == 0 || string.IsNullOrWhiteSpace(providerName))
            {
                return string.Empty;
            }

            try
            {
                var fullPath = string.Empty;
                var fileName = Path.GetFileName(file.FileName);
                if (fileName == null)
                {
                    return string.Empty;
                }
                
                var provider = VirtualPathHandler.GetProvider(providerName) as VirtualPathNativeProvider;

                if (provider != null)
                {
                    fullPath = Path.Combine(provider.LocalPath, fileName);
                    file.SaveAs(fullPath);
                }

                return fullPath;
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }
#142023
Nov 26, 2015 15:37
Vote:
 

The unified file system is no longer used for content in CMS 9, then there is no same thing as the above code works in CMS 9.

1. Now you must migrating the VPP-based files to the new media system: http://world.episerver.com/documentation/Items/Upgrading/EPiServer-CMS/75/Migrating-VPP-based-files-to-the-new-media-system/

2. Programmatically uploading to the new system: http://world.episerver.com/documentation/Items/Developers-Guide/EPiServer-CMS/9/Content/Assets-and-media/Working-with-media/

#142029
Nov 27, 2015 2:42
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.