Reza on blogging [MVP]

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

Subscriptions

<July 2009>
SuMoTuWeThFrSa
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

News



toronto.sharepoint.camp


Navigation

Post Categories

Other Bloggers

Personal Links

This blog is now closed. Please update your links!

After blogging here for > 3 years, I've decided to move my blog to http://blogs.devhorizon.com/reza .That's mainly because anonymous comments stopped working and I also lost my comments in this blog at one point. I have gone ahead and spent more than 6 hours to fix the problem and find a way to get my comments back, but no luck. I can't afford spending more time on issues of this kind especially when I can build a new blog in less than 1 hour while I was waiting for my next flight to Dubai!!  

There was already a redirector at http://blogs.devhorizon.com/reza to redirect the traffic to this blog. I removed that redirection and built the new blog at that address, so if you were using that URL to get to here, please be informed that from now on, you will be redirected to the new blog. RSS feed has also changed to http://feeds.feedburner.com/RezaAlirezaei . See you in my new blog!


posted Thursday, November 22, 2007 8:29 PM by rezaa with 0 Comments

Installing Team Foundation Server in single Server Mode (WSS 2.0)

I have installed TFS couple of times, but it has been always in a dual-server mode which basically puts the Team Foundation data and the application tiers on separate computers. Last week, I was asked by a colleague of mine to give him a hand on installing TFS in a single server mode. Well, I am not a TFS expert, but when it comes to a technology that somehow relates to SharePoint somewhere, I step in and learn enough about that technology to protect myself for rainy days in future. As a result, I have been involved in many integration projects that SharePoint is the other end or it is used under the hood. Despite the fact that I am known for 100% SharePoint architecting and dev , I *really* enjoy this type of work a lot more.It is much more fun plus the exposure you can get to other complementary technologies around SharePoint. Obviously, the challenge is always to stay focused and indeed not to be derailed.

Okay, back to the issue. I agree wholeheartedly that
TFS documentation is really good , but I think it is a bit complicated for many users, definitely lacks some screenshots and a very important tip which is the fact that TFS expects SharePoint configuration database to be called STS_Config_TFS. One other thing that I have found very important (and not emphasized enough in the documentation) is to create and use right user accounts for various steps during the installation process.Having said this , I decided to create a document that describes the installation steps in a more summarized way along with many screenshots of the important steps. You can download this document here and please let me know what you think.


posted Sunday, November 04, 2007 2:02 AM by rezaa with 0 Comments

Calling all volunteers for Toronto SharePoint Camp 2007!!

Toronto SharePoint Camp 2007 is only 3 days away – and we need your help. 

If you have already registered to help us or if you are interested, then tonight is the right time to get more involved.Please join other volunteers at 6:00pm at the Toronto SharePoint User Group venue at 2 Bloor West, so that we can allocate job roles, functions, and responsibilities surrounding the event this Saturday.

Thank you in advance for donating your time to support the Toronto SharePoint Camp 2007.

See you tonight,


posted Wednesday, October 17, 2007 1:26 PM by rezaa with 0 Comments

Getting user login from the PeopleEditor via Code

Assuming you have a people editor control defined like below:

<wssawc:PeopleEditor AllowEmpty="false"  ID="myPeopleEditorControl" runat=server SelectionSet="User" MaximumEntities="1" MultiSelect="false" AllowTypeIn="false" Width='500px' />

The following code sample will get you the currently logged on user's login from the PeopleEditor control:

  ArrayList peEntities = myPeopleEditorControl.Entities;
  PickerEntity pickEn = (PickerEntity)peEntities[0];
  stringLogIn = pickEn.Key;

This comes handy when you want to create an SPUser context out of the entities kept in the PeopleEditor control. For example:

 private SPUser GetUser(string logIn)

        {
             SPUser user = this.workflowProperties.Web.SiteUsers[logIn];
             return user;
        }

Don't forget Required Field Validation on your people editor control if you want the code not to break on you.


posted Thursday, October 04, 2007 2:56 PM by rezaa with 0 Comments

Toronto SharePoint Camp 2007 Count down

The Toronto SharePoint Camp 2007 is just around the corner, 20th of October in Toronto. Register Today, Space is limited!

Remember, this is a *Free* event and no matter how expert you are in SharePoint, there should be something there for you to learn. For those of you who keep sending me emails asking for events and opportunities to learn MOSS 2007, there you are! Here is a great opportunity to meet a lot of SharePoint guys, learn for top-notch industry experts plus a lot of fun and PRIZES!!!

I have two demos prepared one targeting the advanced audience and the other one for beginners. I probably have to choose one of them if there are many speakers lined up.

Please keep an eye on my blog, Eli’s blog and SharePoint Buzz blog for updates and  announcements

 




posted Sunday, September 30, 2007 11:02 PM by rezaa with 1 Comments

Item Level Permission in workflow CreateTaskXXX activities

I wish there was an easier way of incorporating item-level security into "CreateTask" and "CreateTaskWithContetType" activities other than what SPWorkFlowTask offers.I think this is a serious requirement for many clients who asks for a process to be modeled by workflow and therefore there should be an easier way to accomplish it. sadly,workflows assume that users already have permission to access the task list and once the tasks are created by workflow, you are basically on your own to set up the required permissions. If you fail to properly set the required permissions on item level basis and aside from the issue described above, assignee might get an email regarding the new task , click on link and boom ...... ugly "Access Denied" will be thrown at his face. There is a sample activity here that you can check out , but for me it only worked in SharePoint designer and I was never able to get it to work as an activity in my custom workflows not written in SPD.

Here is the way I do it:

1) I create the Task using "CreateTaskWithContentType" activity from my workflow. Obviously, I already have a content type in place.

2) I have also attached an event handler to the content type I use above. Oops! I forgot to say that there is no way you can visually do that (except this one), so I use a programmatic approach to assign an event handler to my content type when the feature that contains my content type get activated.

3) So I have to create a Feature that contains the content type (MyTaskContentType.xml is content type definition which I will skip for the sake of code brevity)
<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="5FED1202-C6B8-453e-9EC0-F328655ED4DC"
  Title="My Workflow Task Content Types"
  Description="...."
  Version="12.0.0.0"
  Scope="Site"
  xmlns="http://schemas.microsoft.com/sharepoint/"
  ReceiverAssembly="DevHorizon.SharePoint.Workflows, Version=1.0.0.0, Culture=neutral, PublicKeyToken=207a12b7817b805c"
  ReceiverClass=" "DevHorizon.SharePoint.Workflows.AddConentTypesEventHanlders">

<ElementManifests>
  <ElementManifest Location="DivRepTask.xml" />
  <ElementManifest Location="HRAdminTask.xml" />
</ElementManifests>

</Feature>

4) I create a feature receiver class for this feature, I get a reference to the content type and attach the event handler to it programmatically:

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            using (SPSite siteCollection = (SPSite) properties.Feature.Parent)
            {
                using (SPWeb web = siteCollection.OpenWeb())
                {
            System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly();                   
                    SPContentType ctMyTask = web.ContentTypes["My Conent Type"];
                    ctMyTask.EventReceivers.Add(SPEventReceiverType.ItemAdded, a.FullName,"MyTaskItemEventReceiver");
                    ctMyTask.Update();
                    web.Update();
           
                 }
              }
          }

5)  Now,I need to create an event handler class named "MyTaskItemEventReceiver" that inherits from SPItemEventReceiver.Make sure you decorate this class with the right attributes to target to the featureId that contains your content type and the content type Id that you are writing this event handler for. You also need a unique GUID for your event handler

           [TargetContentType("feature id goes here", "content type id goes here")]
           [Guid("and here is the unique id for your enevnt handler")]


6) In ItemAdded method of your event handler add the following code:

            DisableEventFiring();
            SPListItem listItem = properties.ListItem;
            try
            {
                listItem.BreakRoleInheritance(false);
                listItem.Update();
                listItem =SetItemLevelPermissions(listItem.Web, listItem, SPRoleType.Contributor, listItem["Assigned To"].ToString());
                listItem.Update();
            }
            catch (Exception ex)
            {
                try
                {
                   //Add error handling code here
                }
                catch { }
            }

            EnableEventFiring();

7) And finally add this helper method somewhere accessible from within your event handler

         public static SPListItem SetItemLevelPermissions(SPWeb setSPWeb, SPListItem setListItem, SPRoleType setRoleType, string assignedTo)
        {
            int index = assignedTo.IndexOf(';');
            int id = Int32.Parse(assignedTo.Substring(0, index));
            SPUser user = setSPWeb.SiteUsers.GetByID(id);
            SPRoleDefinition roleDefinition = setSPWeb.RoleDefinitions.GetByType(setRoleType);
            SPRoleAssignment roleAssignment = new SPRoleAssignment(user.LoginName, string.Empty, string.Empty, string.Empty);
            roleAssignment.RoleDefinitionBindings.Add(roleDefinition);
            setListItem.RoleAssignments.Add(roleAssignment);
            return setListItem;
        }

Now when your workflow creates a task, its item level permission will be broken and set to "assigned to" field.Happy ending!


posted Thursday, September 27, 2007 2:00 AM by rezaa with 0 Comments

Programming under the influence

Let’s say you have a list (i.e.task list ) for which you need to capture ItemAdded event using an event handler and You have to do something unusual like the following:

        [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
        public override void ItemAdded(SPItemEventProperties properties)

        {
            SPListItem testtask = properties.ListItem.ParentList.Items.Add();
            testtask["Title"] = "You are fired!::" + DateTime.Now.ToString();
            testtask["Due Date"] = DateTime.Now;
            testtask["Priority"] = "(1) High";
            testtask.Update();
        }

 

Congradulations! You are trapped in a loop. How? Somebody adds  a task and your event handler fires and adds another task and  so on and so forths. I know this may sound stupid to do, by my point is something else here. Event handler OM is now smart enough not to let you get trapped in an infinite loop ,so recursion depth in such case is set to 10 (for itemAdded) and looping only occurs 10 times. It is really cool! Look at the picture below:

 If you really have to do such a thing then at least use DisableEventFiring() and EnableEventFiring(); to stop the event handler from firing 10 times. 

        [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
        public override void ItemAdded(SPItemEventProperties properties)

        {
            DisableEventFiring();
            SPListItem testtask = properties.ListItem.ParentList.Items.Add();
            testtask["Title"] = "You are fired!::" + + DateTime.Now.ToString();            
            testtask["Due Date"] = DateTime.Now;
            testtask["Priority"] = "(1) High";
            testtask.Update();
            EnableEventFiring();
        }


posted Wednesday, September 26, 2007 4:34 PM by rezaa with 1 Comments

Plan your three Must-Attend conferences in 2008

1) Microsoft Office System Developer Conference 2008 | San Jose, California | Feb 10-13 2008

I was just informed that the official site for this has gone live. I think this is the first time ever this conference is open to the public, so everyone is invited. This is a fantastic opportunity for architects, developers, industry experts, and Microsoft insiders to come together to discuss various developing solutions in Office System.

2) SharePoint 2008 conference | Seattle,WA | March 3-6,2008

Take advantage of  the "early bird" special discount. Register Today

3) Tech·Ed | Orlando, FL | June 9-13, 2008

Be among the first to get conference information, session agendas, and preregistration details by signing in the Tech·Ed 2008 Guestbook.

If you live in Greater Toronto Area, I'd highly recommend you to mark your calendar for 20th of October for Toronto SharePoint Camp. I can't wait to see you all there! 


posted Monday, September 17, 2007 7:32 PM by rezaa with 0 Comments

Toronto SharePoint Camp: Saturday, October 20, 2007

I've just come back from vacation and I am very pleased to announce The first ever SharePoint Camp being held in Toronto on Saturday, October 20, 2007. I duplicate what Eli has posted in his blog because no one in Greater Toronto Area(GTA) should miss this great opportunity. For most updated information on this event keep an eye on Eli's blog.

Mark your calendar! The first ever SharePoint Camp will be in Toronto, and registration will be absolutely free.

Toronto SharePoint Camp, Manulife Centre
200 Bloor Street East
Saturday, October 20

The event will be hosted by the Toronto SharePoint User Group with a supporting cast of many fantastic volunteers and guest speakers.

There are 3 tracks: Developer, Administrator, and Champion/Architect. There will be 15-18 presentations total in 3 to 5 theatres. The space should comfortably accomodate 200 to 300 attendees. We'll follow the CodeCamp manifesto: free, volunteer-run, brand-agnostic, less talk, more rock. 

Call for speakers: All submissions must be delivered by September 21, 2007. Presentations and demo code is due by October 12, 2007. Read more about how you can contribute and apply by downloading the Call For Speakers today!

Call for Volunteers:  If you'd like to help out, mark your calendar for October 17 and 20 today. Then, watch this blog for link to the sign-up sheet as soon as the site goes live. On Wednesday, October 17th at 6:pm we'll have a pizza meeting for about an hour at 2 Bloor Street West (Nexient) to get organized. Note that this is the regular time and location of the SharePoint User Group meeting which will be replaced in October by the Organizer's Meeting (note: in September TSPUG will have a great workflow presentation by K2).

Registration: The website will be up asap, watch Eli's blog for the announcement to be the first in line.


posted Thursday, September 13, 2007 3:49 PM by rezaa with 1 Comments

The latest MOSS and WSS SDK release

There has been a major update to the MOSS and WSS Software Development Kit (SDK) which makes this release an important one.Now there are more samples and articles included and a series of new tools and features are nicely packaged up in the download files.You can install them from the following locations:

MOSS 2007 SDK 1.2:  Includes Conceptual and Class Library Reference documentation, Web Services documentation, and Developer Tools and Samples for MOSS and WSS. http://www.microsoft.com/downloads/details.aspx?FamilyId=6D94E307-67D9-41AC-B2D6-0074D6286FA9&displaylang=en
 
WSS 3.0 SDK 1.2:  Includes Conceptual and Class Library Reference documentation, Web Services documentation, and Developer Tools and Samples for WSS technology *only*. http://www.microsoft.com/downloads/details.aspx?familyid=05E0DD12-8394-402B-8936-A07FE8AFAFFD&displaylang=en  

As you can see in the download page there has been a ton of new features added to this release such as follow:

  1. New Start Menu shortcut : A quicker access to documentation and welcome page
  2. You now have a choice of installation location when you're installing the SDK 
  3. Offline Experience Improvements: More Technical Articles, Visual How-to Articles, and Book Excerpts—plus the Excel Services and Excel 2007 Windows Compute Cluster Server 2003 Job Submission Developer Guide are packaged into one searchable CHM file ( Some of the elements such as WMV files and screencasts are still not available offline)
  4. New Tools and samples: There are many new tools and samples included in this release as follow:
    • Microsoft Business Data Catalog Definition Editor: I am so glad that what I was shouting here  8 months ago finally came into the consideration.Although it is not as complete as BDC Meta Man, I'm sure it is still better than nothing:)
    • WSHelloWorld Web Service
    • Excel Services User Defined Function Sample
    • WSOrders Custom Proxy Sample
    • SAP Sample
    • Sample Protocol Handler
    • Custom Content Source
    • IRM Document Protector
  5. Revised MOSS SDK conceptual topics such as :
    • How to: Create a Minimal Master Page
    • Provisioning Portal Sites
    • Portal Site Template File
    • Portal (Portal Site Template)
    • Webs (Portal Site Template)
    • Web (Portal Site Template)
  6. New MOSS SDK conceptual topics such as :
    • How to: Customize RSS for the Content Query Web Part
    • How to Create a Web Service Connection by using the Business Data Catalog Definition Editor
    • How to Create a Database Connection by using the Business Data Catalog Definition Editor

Here are the links to the online versions:

http://msdn2.microsoft.com/en-us/library/ms550992.aspx

http://msdn2.microsoft.com/en-us/library/ms441339.aspx

 


posted Saturday, August 25, 2007 12:36 AM by rezaa with 0 Comments

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

Adding and Removing keys from appSettings in web.config

Today, I was struggling with adding and removing entries from web.config/appsettings in my feature receiver class. Well, it was quite easy to add , but removing was giving me a real hard time. I used my perfect indexing tool and I came across these great posts from Daniel Larson  and Tony Bierman. By first look at their posts I realized that removing requires a *right* call to SPWebConfigModification constructor, otherwise it won't ever happen. Both posts are for adding Ajax http handlers, but one can easily alter them to make the solution work for appsettings as well. 
 
protected void ModifyWebApplication(SPWebApplication app, bool removeModification)
{
SPWebConfigModification modification = new SPWebConfigModification("add[@key='TotalDigits']", "configuration/appSettings");
modification.Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode ;
modification.Value = "<add key=\"TotalDigits\" value=\"21\" />";
modification.Sequence = 0;
if (removeModification)
   app.WebConfigModifications.Remove(modification);
else
   app.WebConfigModifications.Add(modification);
SPFarm.Local.Services.GetValue().ApplyWebConfigModifications();
 
}


As Daniel has mentioned in his comments, a real benefit of using the SPWebApplication in your code is that the changes are applied to the farm, since the SPWebApplication represents that virtual web application that lives in the farm context.Thanks Daniel and Tony!


posted Sunday, August 12, 2007 10:03 PM by rezaa with 0 Comments

SPFeatureDependencyCollection

You can programmatically find all activated features that are dependent on a specific feature by using the following example. In this example, feature is stopped from being deactivated because dependant features are still in active mode.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Collections;
using System.Diagnostics;

namespace Configuration
{
public class Configurator : SPFeatureReceiver
{
public override void FeatureInstalled(SPFeatureReceiverProperties properties) {}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties) {}
public override void FeatureActivated(SPFeatureReceiverProperties properties) {}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
        SPSite site = properties.Feature.Parent as SPSite;
        SPFeatureCollection spfeatCol = site.Features;
        //iterate through all the features of the current site collection
       foreach (SPFeature feature in spfeatCol)
          {

          // Get the collection of all features that are dependent on this feature
         SPFeatureDependencyCollection depCollection = feature.Definition.ActivationDependencies;
         foreach (SPFeatureDependency featureDependency in depCollection)
                {
                if (featureDependency.FeatureId.Equals(properties.Feature.DefinitionId) && feature.Definition.Status.Equals(SPObjectStatus.Online))
                        {
                         throw new Exception("Deactivation aborted! There is at least one dependant feature in active mode.");
                         }
                 }
           }


// Do the rest of the work here.

}
}
}


posted Tuesday, August 07, 2007 7:58 PM by rezaa with 0 Comments

non CLS-compliant classes in SDK, what that means?

When you browse SharePoint SDK , you come across some classes such as ContentByQueryWebPart which is marked as non CLS-compliant classes. This class or any derived type may not be interoperable with a wide range of .Net supported programming languages.Something that you really need to consider when using this calss or driving your custom types off of it. Generally, C# complier does not check for CLS compliance of your code and you have to explicitly instruct it to do so.

This class for whatever reason is not decorated to be CLS-compliant and it should be used with extra caution in regards to interoperability.

[CLSCompliant(false)]
public class ContentByQueryWebPart : CmsDataFormWebPart
{
.....
}


posted Monday, July 30, 2007 4:00 PM by rezaa with 0 Comments

External Hard Drives and SharePoint

I have used both types of external drives (USB2 and 1394 connections) for my SharePoint images and the USB2 drives always perform better than firewire drives for me. 1394 drives sometimes give me headaches after restart and I basically have to unplug and plug it back in ,so keep this in mind as the first tip.

SharePoint is a resource intensive product and on the top of that a virtualized SQL server adds too much overhead so you can never expect the same performance and transfer rate you get with IDE/SCSI.None of the existing external hard drives are meant to give you such a performance.

If you are performing backups as well then consider getting two drives, one dedicated to your sharepoint images and the other one for storing your backups. I will never store backups side-by-side my images.A large external hard drive ( 250GB or greater) is necessary.

Remember, Most of external hard drives come pre-formatted so always check to see what file format is used at first place before you start creating your demo or non-demo images. By creating a VHDs on FAT32 ,Virtual PC splits it to multiple files which may not be what you want so you have to take extra steps to merge them all.

At the end and for Vista Users in particular, always make sure that the external hard drive you are about to purchase has no compatibility issue with your OS. I know some people who had problem hooking up their Western Digital 500 GB External HD and they are still stuck!


posted Monday, July 30, 2007 1:17 PM by rezaa with 0 Comments

Working with property bags

1) Definitely make sure that you call update method when you are done adding property bags, otherwise your changes won't be applied.

curWeb = SPContext.Current.Web;
curWeb.Properties.Add("MyProperty", DateTime.Now.ToString());
curWeb.Properties.Update();
 
2) In some cases I have found that SPWeb.Properties.Remove("MyProperty") does not work even if you call update method after. In those case when I set the property value to null , it will be removed from the collection and SPWeb.Properties.ConstainsKey("MyProperty") does not return “True” which means it is not there.

curWeb = SPContext.Current.Web;
curWeb.Properties["MyProperty"]= null;
curWeb.Properties.Update();

To find out if a property bag exists or not simply check this:

if (curWeb.Properties["MyProperty"] != null)
 {
  //Exists
 }
else
 {
  // Does not Exist
 }


posted Wednesday, July 25, 2007 4:15 PM by rezaa with 0 Comments

Time out during gradual upgrade to MOSS 2007

Situation: Upgrading a large site collection from SPS 2003 to MOSS 2007 for a completely virtualized medium server farm environment. In brief, when you have a large site collection, the data copy for gradual upgrade may time out.

Upgrade log file:[SPSqlCommandFactory] [DEBUG] [10/20/2006 6:26:00 AM]: SqlCommand.CommandTimeout = 23635
[SPSiteCollectionCopier] [DEBUG] [10/20/2006 6:26:00 AM]: Copying table AllDocStreams.
[SPSiteCollectionCopier] [ERROR] [10/20/2006 1:00:00 PM]: Failed copying site SPSite Url=http://devhmoss.
[SPSiteCollectionCopier] [ERROR] [10/20/2006 1:00:00 PM]: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
[SPSiteCollectionCopier] [ERROR] [10/20/2006 1:00:00 PM]: at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParserStateObject.ReadPacket(Int32 bytesExpected)
at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
at System.Data.SqlClient.TdsParserStateObject.ReadByte()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at Microsoft.SharePoint.Utilities.SqlSession.ExecuteNonQuery(SqlCommand command)
at Microsoft.SharePoint.Upgrade.SPSiteCollectionMigrator.SPBaseSiteCollectionCopier.Copy()
[SPManager] [ERROR] [10/20/2006 1:30:00 PM]: Migrate [SPMigratableSiteCollection Parent=SPManager] failed.
[SPManager] [ERROR] [10/20/2006 1:30:00 PM]: This SqlTransaction has completed; it is no longer usable.
[SPManager] [ERROR] [10/20/2006 1:30:00 PM]: at System.Data.SqlClient.SqlTransaction.ZombieCheck()
at System.Data.SqlClient.SqlTransaction.Rollback(String transactionName)
at Microsoft.SharePoint.Utilities.TransactionalSqlSession.Rollback()
at Microsoft.SharePoint.Upgrade.SPSiteCollectionMigrator.SPBaseSiteCollectionCopier.Copy()
at Microsoft.SharePoint.Upgrade.SPSiteCollectionMigrator.Migrate()
at Microsoft.SharePoint.Upgrade.SPManager.Migrate(Object o, Boolean bRecurse)
[SPManager] [DEBUG] [10/20/2006 1:30:00 PM]: Elapsed time migrating [SPMigratableSiteCollection Parent=SPManager]: 21:16:28.3861356.
[SPManager] [INFO] [10/20/2006 1:30:00 PM]: Gradual Upgrade session finishes. root object = SPMigratableSiteCollection Parent=SPManager, recursive = True. 2 errors and 0 warnings encountered.
[SPManager] [DEBUG] [10/20/2006 1:30:01 PM]: Removing exclusive upgrade regkey by setting the mode to none

Events on database server :

  • Autogrow of file 'DevMoss_SITE_Pair_log' in database 'DevMoss_SITE_Pair' cancelled or timed out after 4062 ms.  Use ALTER DATABASE to set a smaller FILEGROWTH or to set a new size.

         OR

  • Autogrow of file 'WSSUP_Temp_cda0b018-aa08-4abe-b752-418c62861754_log' in database 'WSSUP_Temp_cda0b018-aa08-4abe-b752-418c62861754' took 83109 milliseconds.  Consider using ALTER DATABASE to set a smaller FILEGROWTH for this file.

Actions taken: Pregrowing transaction files in pair and temp databases as stated here did not help, neither setting a smaller growth rate to prevent a time-out during the autogrow operation on database server (because it is virtualized and expected to be slow) as described in this KB article .We also tried bumping up the resources on all servers, again no luck!!!

Cause: Due to the inaccurate nature of setting throughput on every upgrade action, and the unpredictability of hardware performance in real time, the timeout computed during upgrade process could sometime break a legit SQL query that is just running a little longer than usual.

Solution: gradual upgrade is not your choice :) Use DB migration!!!!

 


posted Thursday, July 19, 2007 12:41 PM by rezaa with 0 Comments

How to create a timer Job and update its progress.

The following snippet demonstrates how to implement a timer job and update its progress using SPJobDefinition.UpdateProgress. The example provided below is just to show you how to provision a timer job and update its progress and may not relate well to real-world scenarios.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;
using Microsoft.SharePoint.Administration;
using System.Web.Configuration;
using System.Configuration;

public class AutomatcSiteDescUpdater : SPJobDefinition
    {
      
        public AutomatcSiteDescUpdater()
            : base()
        {
        }

        public AutomatcSiteDescUpdater(string jobName, SPService service, SPServer server, SPJobLockType targetType)
            : base(jobName, service, server, targetType)
        {
        }

        public AutomatcSiteDescUpdater(string jobName, SPWebApplication webApplication)
            : base(jobName, webApplication, null, SPJobLockType.ContentDatabase)
        {
            this.Title = "Description Updater";
        }


        public override void Execute(Guid contentDbId)
        {
          
           
            SPWebApplication webApplication = this.Parent as SPWebApplication;
            SPSiteCollection siteCol = webApplication.Sites;
            int siteColCount = siteCol.Count;  //In my example (also shown in the picture below) there were 21 site collections.

            for (int i = 0; i < siteColCount; i++)
            {
                SPWeb rootWeb =  site.RootWeb;
                rootWeb.Description = "Description of this web was last updated on " + DateTime.Now.ToString();
                rootWeb.Update();

                //Update Progress Bar
                this.UpdateProgress((int)(i * 100 / siteColCount));

                //Dispose rootWeb
                if (rootWeb != null)
                {
                    try { rootWeb.Dispose(); }
                    catch { }
                }
            }


        }


Progress gets updated as you refresh the page



posted Friday, July 13, 2007 7:01 PM by rezaa with 0 Comments

RunWithElevatedPrivileges tricks

SPSecurity exposes a method called “RunWithElevatedPrivileges” which gives you an option to elevate the privilege to the application pool identity under which your code is executing. Looks nice, eh?

But Wait a second!! You are not done yet. I wish it was that easy when it comes to impersonation. In order to get this method call to properly impersonate your application pool identity you need to do some more work. Basically, SPSite and SPWeb objects created outside do not have Full Control even when referenced inside the delegate (anonymous method), so you need to find out their GUID before impersonation is performed and re-create the context one more time. Finally,never forget to dispose your objects!

 

//Don't dispose the following two objects. Sharepoint will take care of their disposal when page is completely rendered.
SPWeb  webInUserContext = SPContext.Current.Web;
SPSite SiteInUserContext = SPContext.Current.Site;
               
Guid webGuid = webInUserContext.ID;
Guid siteGuid = SiteInUserContext.ID;

SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    // get the site in impersonated context
                    using (SPSite site = new SPSite(siteGuid))
                    {

                        // get the web in the impersonated context
                        SPWeb web = site.OpenWeb(webGuid);
                   
                       // Do your work here  
                       

                     web.Dispose();
                    }

               });


posted Thursday, July 12, 2007 3:39 PM by rezaa with 2 Comments

Powered by Community Server, by Telligent Systems