Posts

Showing posts with the label MOSS

MOSS Workflow History Association

Based on a lot of the blog sites, SharePoint 2007 (MOSS) has a timer job that will purge the workflow history association with the work item after 60 days. For most of the users, this is not a good thing because our their audit depends on it. I have read a few solutions that can work around this issue. Use a custom list for audit and do not depend on the workflow hisory. Based on Microsoft, workflow history is not intended for audit purposes. You should probably always create a separate audit log. You can write code to log your workflow history or events to a separate list. Try to use folder structure (i.e. year, month, workflow ID, etc...) so that you don't have more than 2000 items in a view/folder. Write code to change the default days from 60 to whatever your requirement is. There is a sample code that was posted on one of the comments in this post(http://social.msdn.microsoft.com/Forums/en-US/sharepointworkflow/thread/b15b27e2-3033-418b-9731-968273d7423e). I have copied and pa...

Close/Open Web Parts Programmatically

I didn't see a lot of post that shows you how to close and open web parts programmatically. I figured I'll writer one just in case I forget how to do it later. You have to work with WebPartManager class for working with web parts. To get the web part manager, you can do the following: SPFile page = site.GetFile("pageUrl") SPLimitedWebPartManager webPartMngr = page.getLimitedWebPartManager(PersonalizationScope.Shared); Once you have the WebPartManager, you can get the web part that you want to close by doing: Foreach (WebPart webPart in webPartMngr.WebParts) { if (webPart.Title == "testWebPart") { webPartMngr.CloseWebPart(webPart); webPartMngr.SaveChanges(webPart); } } The SaveChanges() has to be done else it just won't work. After the web part is closed, you can still find it in webPartMngr.WebParts collection to re-open it. The code is basically the same as how you would close it. Just change the CloseWebPart() to OpenWebPart() instead.

No SPContext for Event Receiver

I have some common methods that use SPContext. I am having problem when I call those methods in my event receiver code. I don't think there is a way to use SPContext in event receiver. To get it working, I have to create an overload method that takes addiational parameters such as SPWeb or SPSite depending on what is needed.

SharePoint Tools and Training

SharePoint Tools: Microsoft Best Practices Analyzer for Windows SharePoint Services 3.0 and the 2007 Microsoft Office System - It's a tool that analyze your sharepoint environment against the best practices. This tool is released by Microsoft. Here is a blog that explains how to run this analyzer tool. SharePoint Training: Office SharePoint Designer 2007 Training Standalone Edition

Send email using MOSS STMP Server

Microsoft.SharePoint.Utilities.SPUtility class provides methods for sending email, SendEmail(). Out-going mail server will have to be configured before it'll work properly.

Trying to use an SPWeb object that has been closed or disposed and is no longer valid error

I have encountered this error ("Trying to use an SPWeb object that has been closed or disposed and is no longer valid.") at 2 different location. The first time, I was trying to dispose the SPSite object that I got from SPContext.Current.Site. According to this post , you shouldn't dispose the SPSite or SPWeb object if it's from the SPContext. You can refer to some of the best practices for disposing sharepoint objects here . So, to resolve this problem, you can either not dispose your object or you can create the SPSite/SPWeb object using a different way and dispose it later. i.e. using (SPSite site = new SPSite ( siteUrl )){}. The 2nd time that I got this error message, I didn't know what was going on and it took me a long time to find out the cause of the problem. I was using PublishingWeb.IsPublishingWeb(SPWeb) method to check if a particular web is a publishing web. After I checked and it is publishing web, I tried to update a list item and then I got t...

Customize EditingMenu, Quick Access, and Site Action

Editing Menu, Quick Access, and Site Action are three of the menu bar in MOSS that are customizable. In C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\EditingMenu, you can find 3 xml files corresponding to each of the menu. Those 3 xml files (EditingMenu.xml, QuickAccess.xml, and SiteActioni.xml) are applied to all MOSS site on the Web Front End server. To customize for just a site collection, you can customize the xml files in the Editing Menu folder in the master page gallery (/_catalogs/masterpage). See more details here . *Note: After each change to the xml file, an application pool recycle or iisreset has to be done before the changes can take effect on the site. The following are the possible errors that you can get when you customize these xml files: "Index was outside the bounds of the array." - There are a lot of causes for this issue. In my case, I set UseResourceFile="true" while I actually typed in the text dire...

How to Customize MOSS Site Manager (Site Content and Structure Page)

MOSS Site Manager page (Site Content and Structure page, _layouts/sitemanager.aspx) in my opinion one of the most important page for Web Content Management in MOSS. However, it is not so easy to custom. As you might be aware that the custom ECM menu (that shows on normal library page) won't be showing up in this page. This post hopefully will provide a starting point for you. To customize it, I did the following things: copy the original siteManager.aspx in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS and create a new file, call CustomSiteManager.aspx. Change the SiteAction.xml in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\EditingMenu if you want to customize for all sites on MOSS environment. Or you can change the customSiteAction.xml at Master Page Gallery -> Editing Menu folder if you only want one site collection to be customized. Basically, you want to point the "Manage Cont...

Debugging and Trouble Shooting in WSS3.0 and MOSS

The followings are a few things that you can use to debug and trouble shoot your custom code in MOSS development environment. Out-Of-The-Box (OOTB) SharePoint logs: The log can be located @ C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS. The detail level of the information can be setup in the Central Administrator. There are a lot of information in those log files. Fortunately, there are tools out there to help you parse and filter the logs (i.e. SpsDev.com ULS Log Reader). Sometimes you'll get unexpected error has occurred on a web page and there is no other information to help you debugging this issue. There is a great post that shows you how you can get rid of the useless unexpected error page and get the standard ASP.net error page for debugging. Change the following line in the web.config <SafeMode MaxControls=“200“ CallStack=“false“… to <SafeMode MaxControls=“200“ CallStack=“true“… and you'll also need to set custom errors to 'Off...

Adding Field to Content Type Programmatically

The following sample code add field to the content type programmatically. The field has to be created as site column first refer to my first blog for how to add field programmatically . It's not really the field that's added to the content type but a reference of the field (It's the same as fieldRef attribute in feature elements xml). SPSite site = new SPSite ( _siteUrl ) PublishingSite pubSite = new PublishingSite(site); SPContentType contentType = pubSite.ContentTypes[ contentTypeName ]; SPField field = pubSite.RootWeb.Fields[ fieldGuid ]; SPFieldLink fieldLink = new SPFieldLink(field); contentType.FieldLinks.Add(fieldLink); contentType.Update(true); Later on if you want to update the FieldLinks (fieldRef), you can get the FieldLink for the field by the same fieldGuid. The following code sample shows how to return the SPFieldLink from content type. foreach (SPFieldLink fieldRef in contentType.FieldLinks) { if (fieldRef.Id == fieldGuid) return fieldRef; }

Create a New Welcome page programmatically

The following code sample creates a new publishing page in a sub site in MOSS and set it to be the welcome page for the sub site. By providing the pagelayout, it knows which content type to use to create the publishing page. private void CreateNewWelcomePage(SPWeb web, PageLayout pageLayout) { if (PublishingWeb.IsPublishingWeb(web)) { PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web); PublishingPage welcomePage = pubWeb.GetPublishingPages().Add("Welcome.aspx", pageLayout); welcomePage.Title = "Welcome Page"; welcomePage.Update(); welcomePage.CheckIn("Initial version"); pubWeb.DefaultPage = welcomePage.ListItem.File; pubWeb.Update(); } }

Create MOSS Site Columns Programmatically

There a few ways to create site column programmatically in MOSS. One of the way is to use AddFieldAsXml(). Using this method give you the ability to create field with a pre-defined GUID. There is a set of minimum attributes that are required in this xml. The following is the sample code. string siteUrl=http://testingportal.com; string fieldXml = ""; string fieldGuid="{21C910B8-BA41-413a-A87E-D0D05AC4A5A8}"; string fieldInternName="customField"; fieldXml = String.Format("<field id="\" group="\" name="\" format="\" type="\">", fieldGuid, fieldInternalName); using (SPSite site = new SPSite (siteUrl)) { using (SPWeb web = site.rootWeb) { rootWeb.Fields.AddFieldAsXml(fieldXml); } } Unfortunately, there is no such method for creating content type. If you want to use pre-defined GUID for your content type, you'll have create it using feature deployment.