November 2008 Entries

I am working on a major version release for the end of this year, some of our webparts are being moved from one namespace to another, and from one WSP into another, new feature id's etc.

So I created a simple windows application, added a couple controls to it, it does the following:

  1. Goes through all our web applications
  2. Looks for sites with the old feature
  3. In those sites, looks for out specific "old" webparts on pages
  4. Records these pages to a file
  5. Records which web parts were being used
  6. Then removes the webparts from the page
  7. Turns off the old feature
  8. Then removes the webparts from the gallery (just to be sure they are gone!)

A little deployment work-
Retract the wsp, remove it, update our file from SVN, install, and deploy the new/updated solution.

Then open the application back up:
(click on button 2 this time IMPORT), pick a file,
Go through the list of sites in the file, turn on the new features (which will create the webparts in the gallery for us)
Then loads each of the pages we removed parts from before, and it creates new webparts and adds them to the pages.

NOW, one of the webparts I planned to add to the page, always threw an exception. Everytime I created an instance of the object with this application it died. So, I went to the class causing problems, and apparently in the constructor, there was a line...

m_currentWeb = SPContext.Current.Web;

I want to hit something, first of all, there should not be a reference to SharePoint in the constructor, especially not something using SPContext, becuase, it can never be used outside of an application running IN SharePoint. BAH. Moved the line into the CreateChildControls override and life is all good again.

The application finishes up, and our old webparts are replaced by our new ones. Ah another working application to save me time.
(manual work 10%, automated 80%, dubgging problems across projects and solutions, priceless!)

Now to gather publishing state of pages, so we do not have to manually approve all the already approved pages... here comes v2.0!

Andrew Connell mentioned this site in a podcast, it is a must see!

http://www.microsoft.com/click/sharepointdeveloper/html/
Just saw this show up on the MSDN blogs, SPDisposeCheck is a new console tool that MS plans to release to help check for SP objects that have not been disposed of.

Sounds like it will help clean up some memory leaks, and cleanup alot of developer code in the process.

Keep an eye out for the tool from MS!
I was looking for the data I needed to hide a link on a document library settings page, I found that someone had already compiled a list: here and I was able to find my entry and hide it nicely.

Thanks for the post!
I was fumbling around with this for a couple minutes, and then found what I was looking for.

Searching on Google, provided no info for me though, so I thought I would go ahead and writeup a small entry for it.

Basically when working with SPLists, and more specifically SPFields, say we want to create a new column on a list (I will skip content types at this point, it is a whole other entry ), you can setup most of what you like with the base SPField object.

When adding a column, you could...

if (!currentList.Fields.ContainsField("newColumn"))
{
currentList.Fields.Add("newColumn", SPFieldType.Number, false);
currentList.Update();
}
return currentList.Fields["newColumn"];

and you see the type of the fields in the enum SPFieldType.

Awesome, we have a new column named newColumn, and it is a number!
And now you ask,
"But now wait, how do I change specific properties like, allow multiple selections? I have looked all over the object and cannot find it."

So, here we are, use the more specific types, SPFieldNumber.


if (currentList.Fields.ContainsField("newColumn"))
{
SPFieldNumber newColumn = currentList.Fields["newColumn"] as SPFieldNumber ;
newColumn.MaximumValue = 100;
newColumn.Update();
}

So you can see, now we have the actual properties on the object that we see on the standard web/gui add/edit column view.

There is no multiple selection for number, but if you use SPFieldUser you should see AllowMultipleValues, set it to true, update the object, and you are good to go!