Search

Rss Posts

Rss Comments

Login

 

Posts from June, 2008

Recovering from a deleted site collection

Jun 29

How to recover a from a site collection when you get the “404” error page.

1.You would either need a backup of the site collection or
2.SQL backup

Here is how to restore using the SQL backup.

1. Create a new database and restore (through SQL Server)
2. At the command prompt, use stsadm command to add the content database to your site
stsadm.exe -o addcontentdb -url <your url> -databasename <content database> -databaseserver <database server name>
3. Run an IISRESET
4. Go to Central Administration and look at the list of content databases for your web application (under Application Management).  There should be two (the old one – with zero sites – and the new one just attached).  Delete the old database.

Site Collections getting deleted mysteriously

Jun 20

I was presented with the following problem in which sites were getting deleted by a SharePoint bug. The following entry is the steps I went through to determine the issue.

So, the first question I ask myself was. How do sites get deleted?

Via the UI but that would be difficult for an administrator to delete over 300 site collections

Via the API would required someone to write code

SPSite oSiteCollection = new SPSite(“http://” +     System.Environment.MachineName + “/sites/Site_Collection”);
oSiteCollection.Delete();
oSiteCollection.Dispose();
 
After extensive research and using tools such as:

ULS Logs
Netmon
ADO.Net Tracing
DbgView
TDIMon
 
The issue only occurs on a content database there are no errors on the event log. So what now?

The timer job that was running was either deleted using the Central Admin or Stsadm. Multiple jobs were scheduled before the completion of the current running job. So, the deletion of multiple sites was due to the timer job and user.

If there is another move operation scheduled while the  current timer job is running, there will be two move operations at the same moment. This will cause data loss or even massive site collection loss.

A New Job, A New Beginning.

Jun 12

Today I handed in my resignation at my current employer.

The new job came looking for me. It’s great to know someone appreciates my skills in effect; I’ve been head-hunted. It’s a great feeling.

I got one week left with my current employer before I start my new job as a SharePoint Architect with a project that consist of half a million employees.

SharePoint closed views for lists

Jun 10

My resolution to the close views for lists

If end user closes the web list web part using the X on the right corner the CAML query and some of the properties get modified. Which prevents the view from displaying the data that should be presented?
That does not mean that the view is corrupted nor the web part is close but there is no way to modify the view. There is a hidden property for the SPView class but setting the value to true does not redisplays the view.
Web parts that are close by passing the var contents=1 on the URL has nothing to do with the views that are not displaying. Microsoft mentions installing the SP1 for SharePoint which does nothing in relation to the views. The problem is CAML query gets modified.

 

In my opinion the views not displaying any data has to do with the migration.

Original CAML query (Broken)

“<View Name=\”{4222E59E-8879-49F7-AB9D-750A261F851C}\” DefaultView=\”TRUE\” Type=\”HTML\” DisplayName=\”All Documents\” Url=\”/sites/AES/Shared Documents/Forms/AllItems.aspx\” Level=\”1\” BaseViewID=\”1\” ContentTypeID=\”0x\” ImageUrl=\”/_layouts/images/dlicon.png\” ><Query><OrderBy><FieldRef Name=\”FileLeafRef\” /></OrderBy></Query><ViewFields><FieldRef Name=\”DocIcon\” /><FieldRef Name=\”LinkFilename\” /><FieldRef Name=\”Modified\” /><FieldRef Name=\”Editor\” /><FieldRef Name=\”LinkCheckedOutTitle\” /></ViewFields><RowLimit Paged=\”TRUE\”>100</RowLimit></View>”

New CAML after creating a new view

“<View Name=\”{8BAFCD7D-B199-445F-8D6C-F9D625E1D08D}\” DefaultView=\”TRUE\” Type=\”HTML\” DisplayName=\”All Documents\” Url=\”/sites/AES/Shared Documents/Forms/AllItems.aspx\” Level=\”1\” BaseViewID=\”1\” ContentTypeID=\”0x\” ImageUrl=\”/_layouts/images/dlicon.png\” ><Query /><ViewFields><FieldRef Name=\”DocIcon\” /><FieldRef Name=\”LinkFilename\” /><FieldRef Name=\”Modified\” /><FieldRef Name=\”Editor\” /><FieldRef Name=\”LinkCheckedOutTitle\” /></ViewFields><RowLimit Paged=\”TRUE\”>100</RowLimit><Aggregations Value=\”Off\” /></View>”

 

What is the difference in the views.

The original view(broken). The query does not work because of the two  “\”

<Query>

                <OrderBy>

                                <FieldRef Name=\”FileLeafRef\” />

                </OrderBy>

</Query>

 

 

Should be

<Query>

   <OrderBy>

      <FieldRef Name=”FileLeafRef” />

   </OrderBy>

</Query>

 

Re-Created View – Sample code not for production

  SPSite siteUrl2 = new SPSite(textBox1.Text);
  SPWeb myWeb = siteUrl2.OpenWeb();

             myWeb.AllowUnsafeUpdates = true;

 

             SPList listtoinsert = myWeb.Lists[newValue.Text];
             SPView defaultView = listtoinsert.DefaultView;


 

            listtoinsert.Hidden = true;
            listtoinsert.OnQuickLaunch = true;
            listtoinsert.EnableVersioning = true;
            listtoinsert.Update();

            listtoinsert.Fields.AddFieldAsXml(“<Field DisplayName=\”NewField\” Type=\”Boolean\” Required=\”FALSE\” Name=\”NewField\” CanToggleHidden=\”TRUE\” Hidden=\”TRUE\”/>”);

            // Create new view columns
            StringCollection viewFieldCollection = new StringCollection();

 

            // Add field to collection
            viewFieldCollection.Add(“DocIcon”);
            viewFieldCollection.Add(“Author”);
            viewFieldCollection.Add(“LinkFilename”);
            viewFieldCollection.Add(“Last_x0020_Modified”);
            viewFieldCollection.Add(“Modified_x0020_By”);
            viewFieldCollection.Add(“LinkCheckedOutTitle”);

 

            // Create default view query
            string defaultQuery = “<OrderBy><FieldRef Name=\”FileLeafRef\” /></OrderBy>”;

            // Get default view information and delete
            try
            {

                Guid oldViewId = listtoinsert.DefaultView.ID;
                listtoinsert.Views.Delete(oldViewId);

            }
            catch

            {

            }

            try

            {

                listtoinsert.Views.Add(“All Items”, viewFieldCollection, defaultQuery, 100, true, true);
                listtoinsert.DefaultView.DefaultView = true;

            }

            catch

            {

            }

            try

            {

                listtoinsert.Hidden = true;
                listtoinsert.OnQuickLaunch = true;
                listtoinsert.EnableVersioning = true;
                listtoinsert.Update();

            } // try

            catch (SPException sp) { }

            myWeb.Close();

        }

 

Adding Users to An Existig Role Programmatically

Jun 01

SPSite site = new SPSite(http://laptopdev/sites/eddyblanco);
SPWeb web = site.AllWebs[0];
SPUser user = web.AllUsers["laptopdev\\eddy"];
SPGroup grouptoadd = web.Groups["Full Control"];
grouptoadd.AddUser(user);