Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

VirtualPathProvider not working after upgrade

Vote:
 

I was using a virtual path provider in my CMS5 website to store my files in a SQL database

and i was registering it in the hosting environment using Sunali workaround HERE and it was working fine both local and on the server.

But after upgrade the virtual path provider was crashing .. i removed the registeration and it worked fine local but when deploying to the server the site is working but it can't see any of my database files and retrieves nothing.

Can please advice where may be the problem?

#55724
Dec 14, 2011 11:43
Vote:
 

Are you using a custom VPP or one of the built in ones from EPiServer?

Frederik

#55727
Dec 14, 2011 12:45
Vote:
 

Custom VPP. and i registered it in episerver.config

<add showInFileManager="true" virtualName="Upload" virtualPath="~/Upload/" bypassAccessCheck="false" name="Upload" type="CMS.Modules.VirtualPathProvider.VirtualPathDatabaseProvider,CMS.Modules.VirtualPathProvider" connectionStringName="CMS.Data.Properties.Settings.Upload_ConnectionString" physicalPath="" />

#55728
Dec 14, 2011 12:52
Vote:
 

Could you post the code for VirtualPathDatabaseProvider.

Frederik

#55729
Dec 14, 2011 12:53
Vote:
 

#region Fields

        private string connectionString;
        private DbDirectory mRoot;

        #endregion

        #region Constructors

        public VirtualPathDatabaseProvider(string name, NameValueCollection configParameters)
            : base(name, configParameters)
        {
        
            base.ValidateAndSetupConfigParams();
            this.connectionString = VirtualPathProviderConnectionString.GetConnectionStringByName(configParameters["connectionStringName"]);
            VirtualPathProviderConnectionString.CreateInstance(name, this.connectionString);
            this.mRoot = this.GetRootDirectory();
            if (this.mRoot != null)
            {
                string root = this.mRoot.Name;
                if (!String.IsNullOrEmpty(root))
                {
                    base.VirtualPathRoot = root;
                }
            }
        }

        #endregion

        #region Methods

       
        private DbDirectory GetRootDirectory()
        {
            DbDirectory result = null;
            try
            {
                SqlConnection conn = new SqlConnection(this.connectionString);
                try
                {
                    DirectoriesTableAdapter ta = new DirectoriesTableAdapter();
                    if (this.connectionString != null)
                    {
                        ta.Connection = conn;
                    }
                    DbDirectoryDS ds = new DbDirectoryDS();
                    ta.FillRootDirectory(ds.Directories);

                    if (ds.Directories.Rows.Count > 0)
                    {
                        DbDirectoryDS.DirectoriesRow row =
                            (DbDirectoryDS.DirectoriesRow)ds.Directories.Rows[0];
                        result =
                            new DbDirectory(row.ID,
                                            row.ParentID,
                                            row.Name,
                                            row.ACL,
                                            this,
                                            VirtualPathUtility.AppendTrailingSlash(
                                                VirtualPathUtility.ToAbsolute(ConfigurationParameters["virtualPath"]))
                                            );
                    }
                }
                catch (SqlException ex)
                {
                    Modules.ErrorTracing.ErrorManager.TraceException(ex);
                }
                catch (Exception ex)
                {
                    Modules.ErrorTracing.ErrorManager.TraceException(ex);
                }
                finally
                {
                    conn.Close();
                }
            }
            catch (ArgumentException ex)
            {
                Modules.ErrorTracing.ErrorManager.TraceException(ex);
            }
            catch (Exception ex)
            {
                Modules.ErrorTracing.ErrorManager.TraceException(ex);
            }
            return result;
        }

        public override bool FileExists(string virtualPath)
        {
            if (this.mRoot == null)
                this.mRoot = this.GetRootDirectory();

            if (virtualPath.StartsWith(this.mRoot.VirtualPath, StringComparison.InvariantCultureIgnoreCase))
            {
                return (this.FindFile(virtualPath) != null);
            }
            return Previous.FileExists(virtualPath);
        }

        public override bool DirectoryExists(string virtualDir)
        {
            if (this.mRoot == null)
                this.mRoot = this.GetRootDirectory();

            if (virtualDir.StartsWith(this.mRoot.VirtualPath, StringComparison.InvariantCultureIgnoreCase))
            {
                return (this.FindDirectory(virtualDir) != null);
            }
            return Previous.DirectoryExists(virtualDir);
        }

        public override System.Web.Hosting.VirtualFile GetFile(string virtualPath)
        {
                if (virtualPath.StartsWith(this.mRoot.VirtualPath, StringComparison.InvariantCultureIgnoreCase))
                {
                    return this.FindFile(virtualPath);
                }
           
                return Previous.GetFile(virtualPath);
        }

        public override System.Web.Hosting.VirtualDirectory GetDirectory(string virtualDir)
        {
            if (virtualDir.StartsWith(this.mRoot.VirtualPath, StringComparison.InvariantCultureIgnoreCase))
            {
                return this.FindDirectory(virtualDir);
            }
            return Previous.GetDirectory(virtualDir);
        }

        public DbFile FindFile(string virtualPath)
        {
            string fileName = VirtualPathUtility.GetFileName(virtualPath);

            DbDirectory fileParentDirectory = this.FindDirectory(VirtualPathUtility.GetDirectory(virtualPath));
            if (fileParentDirectory == null)
            {
                return null;
            }

            DbFile result = fileParentDirectory.GetFile(fileName);

            return result;
        }

        public DbDirectory FindDirectory(string virtualPath)
        {
            DbDirectory currentDirectory = this.mRoot;

            if (virtualPath.StartsWith(currentDirectory.VirtualPath, StringComparison.InvariantCultureIgnoreCase))
            {
                virtualPath = virtualPath.Remove(0, currentDirectory.VirtualPath.Length);
            }

            string[] dirPath =
                virtualPath.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
           
            foreach (string subDir in dirPath)
            {
                if ((currentDirectory = currentDirectory.GetDirectory(subDir)) == null)
                {
                    return null;
                }
            }
            return currentDirectory;
        }

        #endregion

#55730
Dec 14, 2011 12:58
Vote:
 

Hi,

first, as this is a custom VPP, I do not see why you need to register it like in the Sunali link above. A simple VPP registration in episerver.config should be enough.

Also, this looks like an early version of the Database VPP available on EPiCode (http://www.epicode.no). The version on EPiCode has gone through a major upgrade, but still have almost the same database structure. If possible, you should look into getting the EPiCode version going (most work will be comparing database structures and sp's).

For the problem you describe, it sounds strange that it works locally, but not on the server. You need to look into what differences you have between the two environments.

/Steve

#55739
Dec 14, 2011 23:45
Vote:
 

Hi Steve,

Thanks for your replay.

I will check the new upgrades in the EPiCode.

I was using Sunali approach because i publish a precompiled website (Thats why it is working local..soryy i had to mention that early).

#55742
Dec 15, 2011 9:17
Vote:
 

Thanks Steve.

It is working now after getting the EPiCode version and updating the virtual path provider.

#55813
Dec 19, 2011 13:30
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.