Please note that this post was migrated to my new blog platform. There may be bad formating, broken links, images, downloads and so on. If you need an item on this page, please contact me and I will do my best to get it from my backups.
I'm going to start posting a lot of my old Duncan Nuggets (as Dave Burke likes to call them) here for others to start reading. This is the first of a lot to come.
How to move a file from one FileGallery to another
NOTE: This script was written for Community Server 2.1 RTM.
This method uses a stored procedure to move a single file (aka Post) to another File Gallery (aka Section). Attached is an SQL script file named move_file_to_filegallery.zip that when executed, will create a stored procedure named _move_file_to_filegallery in your database.
After the sproc is created, you can execute it by running the following command:
EXEC _move_file_to_filegallery @PostID, @toSectionID, @ClearTags
You need two bits of information beforing executing:
- @PostID - This is the PostID of the file you want to move.
- You can find this in the URL by viewing the file in CS' normal File view. For example, if we look up the SDK for CS 2.1 the link is: http://communityserver.org/files/folders/communityserver/entry543125.aspx. So the PostID of this file is 543125.
- @toSectionID - This is the SectionID of the File Gallery you want to move the file to.
- You can find this in the URL by going into the Control Panel, Files, and selecting that File Gallery to manage. For example, the URL for managing the CommunityServer Current Releases folder is: http://communityserver.org/controlpanel/files/default.aspx?sectionid=234. So this SectionID that I want to move the file to is 234.
Following the examples above now that we have the two required integers, we can now execute the sproc to move the file. The line would read:
EXEC _move_file_to_filegallery @PostID = 234, @toSectionID = 543125, @ClearTags = 1
NOTE: It is recommended to always clear the Tags, since they only exist in the previous FileGallery and not the new one. So leave it @ClearTags = 1.
NOTE: It is recommended to always clear the Tags, since they only exist in the previous FileGallery and not the new one. So leave it @ClearTags = 1.
There is also error checking built in, so view the Messages for any errors that may have occurred.