More in this section
Forums / Set-up & Installation / Moving/Renaming files between different Sitefinity databases

Moving/Renaming files between different Sitefinity databases

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Laurent
    Laurent avatar
    2 posts
    Registered:
    25 Feb 2008
    29 Jul 2011
    Link to this post
    Hi there,

    We wanted to build a new website in top of an existent SF instance.

    Warning : The following technique supposed you are familiar with the Sitefinity database and with user-defined function in SQL (CLR). If not, do not attempt to use it, you can break everything in your Images & Documents Library !

    We renamed the files already uploaded in Images and Documents (it was quite a mess).
    To do so
      - Get a copy of the files
      - Rename it on the file system correctly
      - Batch uploaded them to the new DB with correct categories and tags.

    The problem was the upload date. How to change the original date to keep this information ?

    To do so, we used a Hash technique, based on CLR.

    Create a new SQLServerProject to deploy the user defined functions
    using System;
    using System.Data;
    using System.Data.SqlClient;
    using System.Data.SqlTypes;
    using Microsoft.SqlServer.Server;
    using System.Security.Cryptography;
     
    public partial class UserDefinedFunctions
    {
     
        private static HashAlgorithm GetHashAlgotithm(string HashAlgorithmName)
        {
            switch (HashAlgorithmName.ToUpperInvariant())
            {
                case "MD5": return MD5.Create();
                case "SHA1": return SHA1.Create();
                case "SHA256": return SHA256.Create();
                default: throw new ArgumentOutOfRangeException("HashType",
    "Don't know how to create a '" + HashAlgorithmName + "' hash.");
            }
        }
         
        [Microsoft.SqlServer.Server.SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true, SystemDataAccess = SystemDataAccessKind.None)]
        public static SqlBinary Hash(SqlBytes Source, SqlString HashAlgorithmName)
        {
            if (Source.IsNull)
                return null;
            HashAlgorithm ha = GetHashAlgotithm(HashAlgorithmName.Value);
            SqlBinary theHash = new SqlBinary(ha.ComputeHash(Source.Stream));
            return theHash;
        }
    };

    Secondly, you can use this function in SQL to compute files hash and get information you need.
    select a.id,LoweredUrl,DateCreatedLoc, dbo.HashStream(ContentValue, 'md5'as MD5
    from sitefinity.dbo.sf_CmsBinaryContent a
    left outer join sitefinity.dbo.sf_CmsContentBase b  on a.id=b.id
    left outer join sitefinity.dbo.sf_CmsContentVersion c   on a.id=c.id

    All you got to do is to use a inner join between databases to update the creation date.
    Et voilà !

    Thanks to Walden : http://blog.waldenl.com/2009/12/computing-md5-hash-of-varbinarymax-in.html
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    03 Aug 2011
    Link to this post
    Hi Mariano,

    Thank you for sharing your code with our community. I have updated your Telerik Points.

    Greetings,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered