Reza on blogging [MVP]

THIS BLOG HAS MOVED TO: http://blogs.devhorizon.com/reza

Subscriptions

<January 2009>
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567

News



toronto.sharepoint.camp


Navigation

Post Categories

Other Bloggers

Personal Links

Friday, August 24, 2007 - Posts

Landing a site collection in its own content database

One of the many advantages of having site collections over just sub sites is that you can create a content database for each site collection. One of the obvious advantages is when backing up or restoring different pieces of your farm that makes it easier to deal with multiple content databases rather than just a giant content database. There are many other advantages that I am not going to write about mainly because it's been fully documented at TechNet site.

Unfortunately, there is no a straight way to tell MOSS where you want your site collections to land when you move them around or create new ones. MOSS uses a round-robin algorithm to distribute them evenly in the existing content databases. However, there is a UI trick (also used in SPS2003) which still can be used in MOSS 2007.A few days ago I was going through the same process for a client and I thought that it is not a bad idea to blog it here.

We were basically moving a site collection from DEV to QA, both environments were 32-bit, same topology and etc. In other words they were identical in many ways.

DEV :

DEV-1) Run stsadm to back up the site collection
stsadm -o backup -url http://mossdev/mysitecollecionDev  -filename c:\mysitecollecionDev.dat

DEV-2) Copy DAT file (mysitecollecionDev.dat) to QA


QA:

QA-1) Choose between QA-1-1 or QA-1-2

QA-1-1) ARE YOU MOVING IT TO AN EXISTING WEB APPLICATION?

       1) Go to content databases in central admin
       2) Choose your web application name from the drop down box
       3) Take all existing content databases offline (status=offline).
          This doesn't actually take the Site Collections offline, but only prevents any new SiteCollections from being created in these database and that's exactly what we want.
       4) Go to QA-2

QA-1-2) ARE YOU MOVING IT TO A NEW WEB APPLICATION?

      1) Create a new web application
      2) Go to QA-2

QA-2)Create mysitecollecionQA as an "Explicit Inclusion"  managed path (Central Administration--> Application Management--> Managed Paths)
QA-3)Create a site collection exactly in the same level as it was in DEV. In this example it should be http://mossdev/mysitecollecionQA. Make sure that the name you choose for content database at level is the name you want to keep for ever ,because we are going to overwrite into this content database
  
QA-4) Run stsadm to restore the datafile you moved earlier

stsadm -o restore -url  http://mossdev/mysitecollecionQA -filename c:\mysitecollecionDev.dat  -overwrite

QA-5) Confirm that your new site collection is created in the only online content DB that you just created and change the status for all the other databases back to online.


posted Friday, August 24, 2007 12:02 PM by rezaa with 0 Comments

On-the-fly creation of attachments for list items

Here is the code to add an item to a list (task list in this example) programmatically and create and attach a file on the fly. You basically need to encode a set of characters into a sequence of bytes (byte array) and call SPAttachmentCollection.Add method to add the binary representation of your attachment to the list item.

StringBuilder sbLog = new StringBuilder();

sbLog.Append("Accessing root web of the site collection...\n");
SPWeb web = new SPSite("http://moss:21165").OpenWeb();

sbLog.Append("Accessing Task list in the root web...\n");
SPList taskList = web.Lists["Tasks"];

sbLog.Append("Adding a new task item...\n");
SPListItem newTask = taskList.Items.Add();

sbLog.Append("Populating the fields...\n");
newTask["Title"] = "Work hard ,but play harder";
newTask["Due Date"] = DateTime.Now;
newTask["Priority"] = "(1) High";


sbLog.Append("Creating the attachment...\n");
ASCIIEncoding encoder = new ASCIIEncoding();
byte[] bytFile = encoder.GetBytes(sbLog.ToString());
newTask.Attachments.Add("log.txt", bytFile);
newTask.Update();


posted Friday, August 24, 2007 12:57 AM by rezaa with 0 Comments

Powered by Community Server, by Telligent Systems