Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Change Storage Location of FoldersChange Storage Location of Folders
Previous
 
Next
New Post
12/15/2011 9:37 AM
 

I needed to find a way to change the storage location for a large sub tree to "secure - file system". Here is a script that I ended up with.

Note that this will only work if you are running this from SQL Managment Studio and only then if the account that sql server service  is running under has write permission to the portals folder. If one would run this from host > sql one would have to add the database account that the website is runnig from is in the sysadmin role in sql server.

The reason for that is that the script makes use of xp_cmdshell that in the process will rename all files in the given tree to end on '.resources'

At the very beginning of the script you will have to set a few variables to match your environment.

-- this is the absolute path to your portal directory
DECLARE @RootPath nvarchar(255) = 'C:\inetpub\wwwRoot\Portals\0\'

-- the script will perform a like search on that expression. so if you put 'images' in here, the script will migrate all folders that have 'images' in ther folder path!
DECLARE @Identifier nvarchar(255) = 'put_the_root_foldername_here'

-- lookup your mapping id to use the correct folder provider in the foldermappings table
DECLARE @FolderMappingId int = 8
DECLARE @StorageLoactionId int = 1

DECLARE @FolderId int
DECLARE @FolderName nvarchar(255)

DECLARE @FileName nvarchar(255)
DECLARE @FilePath nvarchar(255)

DECLARE folder_cursor CURSOR FOR
    select FolderID, FolderPath from Folders where FolderPath Like '%' + @Identifier + '%'
    
OPEN folder_cursor;

-- Perform the first fetch.
FETCH NEXT FROM folder_cursor into @FolderId, @FolderName
WHILE @@FETCH_STATUS = 0
BEGIN
   
   PRINT 'Now securing ' + @FolderName
    
    DECLARE files_cursor CURSOR FOR Select [FileName], [Folder] From Files Where FolderId = @FolderId
    OPEN files_cursor
        FETCH NEXT FROM files_cursor into @FileName, @FilePath
        WHILE @@FETCH_STATUS = 0
            BEGIN
            Print '...' + @FilePath + @FileName
        
            DECLARE @OldPath nvarchar(255) = Replace(@RootPath + @FilePath + @FileName, '/', '\')
            DECLARE @NewFile nvarchar(255) = @FileName + '.resources'
            DECLARE @command nvarchar(500) = 'rename "' + @OldPath + '" "' + @NewFile + '"'
            DECLARE @result nvarchar(1000)
            EXEC @result = master.dbo.xp_cmdshell @command , NO_OUTPUT
        
            Print '...command execution returned ' + @result
        
            FETCH NEXT FROM files_cursor into @FileName, @FilePath
            END
        CLOSE files_cursor;
        DEALLOCATE files_cursor;

   UPDATE Folders set StorageLocation = @StorageLoactionId, FolderMappingID = @FolderMappingId where FolderID = @FolderId   
     
   PRINT @FolderName + ' is now secure'
   FETCH NEXT FROM folder_cursor into @FolderId, @FolderName
END

CLOSE folder_cursor;
DEALLOCATE folder_cursor;




Cheers,
Philipp Becker, Peppertree Solutions
 
New Post
12/15/2011 12:32 PM
 
HM. Although the script had run sucessfully, the filesync mechanism re-created all fileids later on. So for now I'd say, do not use that script.

Cheers,
Philipp Becker, Peppertree Solutions
 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Change Storage Location of FoldersChange Storage Location of Folders


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out