Tuesday, February 2, 2010

PropertyGrid Control and Complex Type Object

For one of my last projects I decided to use the PropertyGrid Control, I assume it would be nice to use it as an editor for my complex type object.

Cheerful as I was it turn to be not such an easy mission, apparently the PropertyGrid Control can handle privitive types, collections and enums, but when it comes to complex type objects it need to be told what will be the way to edit them.

Here is the PropertyGrid as it was displayed originaly:








As you can see, the complex type “Manager” is not editable !!!

In order to make it editable it needs to be define with Editor Attribute, as such:

[Editor(typeof(MyUITypeEditor),typeof(UITypeEditor))]

In order to use this custom UITypeEditor, we’ll need to create two thins:
1. MyUITypeEditor - Based on the UITypeEditor.
2. UIMyClassEditorForm – The form that will be displayed whenever we’ll click the complex type for editing.

I really wanted this to be generic as I could so my UIMyClassEditorForm contains a PropertyGrid Control for editing the object pass through.

So now, when clicking the Manager property we should be abe to edit it and the screen will look like this:


Here is the source code:

Person.cs
public class Person
{
public enum City
{
NewYork,
TelAviv,
Rome
}

public Person() { }
public Person(string firstName, string lastName,int age, City myCity)
{
this.FirstName = firstName;
this.LastName = lastName;
this.Age = age;
this.MyCity = myCity;
this.Manager = new Person();
}

List children = new List();
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public City MyCity { get; set; }
public List Children
{
get { return children; }
}

[Editor(typeof(MyUITypeEditor),typeof(UITypeEditor))]
public Person Manager{ get; set; }

public override string ToString()
{
return string.Format("{0},{1}", FirstName, LastName);
}

}
MyProperyGridSampleForm.cs
public partial class MyProperyGridSampleForm : Form
{


public MyProperyGridSampleForm()
{
InitializeComponent();
}

private void EditPersonButton_Click(object sender, EventArgs e)
{
Person myTestEntity = new Person();
myTestEntity.FirstName = "John";
myTestEntity.LastName = "Smith";
myTestEntity.Age = 29;
myTestEntity.MyCity = Person.City.NewYork;
myTestEntity.Manager = new Person("Liron", "Leybovich", 33, Person.City.TelAviv);

propertyGrid1.SelectedObject = myTestEntity;
}
}
UIMyClassEditorForm.cs
public partial class UIMyClassEditorForm : Form
{
public object MyClass;
public IWindowsFormsEditorService _wfes;


public UIMyClassEditorForm()
{
InitializeComponent();
TopLevel = false;
}

private void UIMyClassEditorForm_Load(object sender, EventArgs e)
{
this.propertyGrid1.SelectedObject = MyClass;
}

protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
_wfes.CloseDropDown();
}

MyUITypeEditor.cs
public class MyUITypeEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(
ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}


#region Edit Value
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider,
object value)
{
IWindowsFormsEditorService wfes = provider.GetService(
typeof(IWindowsFormsEditorService)) as
IWindowsFormsEditorService;

if (wfes == null) { return value; }

UIMyClassEditorForm form = new UIMyClassEditorForm();

if (value != null)
{
form.MyClass = value;
}
else
{
form.MyClass = new object();
}

form._wfes = wfes;

wfes.DropDownControl(form);

return value;
}
#endregion

}

All the best….
Liron

Tuesday, January 19, 2010

How to update ShowInFileDlg programmatically


At some point in your SharePoint development life time you will probably need to update the ShowInFileDlg attribute of a Site Column.

If you will try to do that by a feature and update the XML with new Field's attributes values, the changes will only take effect on new instances, and will not effect on exsisting ContentTypes or Lists that use these Site Columns.

Programmatically updating the Site Column and the Content Type, the changes will be deployed to the children as well.

Here is a generic method for updating any attribute of the Field element and forcing the changes to the Content Type and its children:

public void UpdateFieldAttribute(string siteCollectionURL, string siteColumnName, string contentTypeName, string fieldAttributeName, string fieldAttributeValue)
{
SPSite site = null;
SPWeb web = null;
try
{
using (site = new SPSite(siteCollectionURL))
{
using (web = site.OpenWeb())
{

SPField siteColumn = site.RootWeb.Fields.GetField(siteColumnName);
XmlDocument fieldSchemaXml = new XmlDocument();
fieldSchemaXml.LoadXml(siteColumn.SchemaXml);
XmlNode fieldXmlNode = fieldSchemaXml.SelectSingleNode("Field");
XmlAttribute attr = fieldXmlNode.Attributes[fieldAttributeName];
attr.InnerText = fieldAttributeValue; ;

siteColumn.SchemaXml = fieldXmlNode.OuterXml;
siteColumn.Update(true);

SPContentType contentType = site.RootWeb.ContentTypes[contentTypeName];

contentType.Update(true, false); //Updating the content type is important or the changes will not be reflected
}
}
}
finally
{
if (web != null)
web.Dispose();
if (site != null)
site.Dispose();
}
}

Thursday, January 14, 2010

SharePoint Search Services Error HRESULT: 0x80040D1B

You might facing an issue when clicking the Search Settings in your SSP:
Exception from HRESULT: 0x80040D1B at Microsoft.SharePoint.Portal.Search.Admin.Pages.SearchAdminPageBase.ErrorHandler(Object sender, EventArgs e) at Microsoft.SharePoint.Portal.Search.Admin.Pages.SearchSSPAdminPageBase.OnError(EventArgs e) at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP._layouts_searchsspsettings_aspx.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

In order to solve this issue you will need to do the following:

  1. Make sure to add the service account to the local SharePoint backup operators group on all SharePoint servers.

  2. Set your service name principle account for your SSP on your SharePoint application server. In order to complete this operation you must install Window support tools. Run these commands and all SharePoint web servers:
    setspn.exe -A HTTP/sharepointsite domain\service account
    setspn.exe -A HTTP/sharepoint.domainname site domain\service account

    (Make sure you have the right privileges to run the setspn.exe, usually you will need the domain admin)

  3. On Central administration - Operations - Services on Server
    Stop Office SharePoint Server Search.

  4. Then go to Central administration - Operations - Service accounts.
    Click on web application pool.
    Under web service choose Windows SharePoint Service Web application.
    Under application pool, choose your Shared Service Provider application pool account.
    Re-enter your password and click ok.

  5. Do iisrest in all SharePoint servers.

  6. In Central administration - Operations - Services on Server
    Restart your Office Server Search.

  7. In Central administration - Application Management - Create or configure Farm's Shared Services.
    In the default SSP and click edit properties.
    In the SSP service credentials enter username and password.
    In the index server category select your index server and then click ok.
    Make sure you wait about 5 minutes. (You need to do this for all SSPs)

Good luck...

Liron

Wednesday, March 11, 2009

MOSS Search PDF 64-bit using IFilter 9


Install the PDF Ifilter 9 for 64-bit

  1. Download and extract the contents of "PDFiFilter64installer.zip" to your local drive.
  2. Double click "PDFFilter64installer.msi" to launch the installer.
  3. Follow the instructions in the installer wizard to complete the installation.
  4. After installing the PDF iFilter, it is recommended that you set your system PATH environment variable to the "bin" folder of the "Ifilter" installation. For example, from the "Control Panel\System\Advanced\Environment Variables" tab, append to PATH "C:\Program Files\Adobe\Adobe PDF iFilter 9 for 64-bit platforms\bin\" and then restart the computer.
  5. Follow the Sharepoint IFilter Configuration Guide

Add the PDF extension to Search File Types

  1. SharePoint Server Search Administration page by adding ‘pdf’ to list of File Types in Search Administration->File Types

Add the PDF File Icon to MOSS

  1. Download the icon for pdf file from http://www.adobe.com/images/pdficon_small.gif , save it to \TEMPLATE\IMAGES directory and name it pdficon_small.gif.
  2. Open the docicon.xml file from .\template\xml .
  3. Add a new Mapping element to the ByExtension element.
  4. Save the docicon.xml file.
  5. Restart IIS using iisreset command line.


Restart all SharePoint services as well as IIS.

  1. Run these command-lines:
    “net stop osearch”. Wait for success message.
    “net start osearch”. Wait for success message.
  2. Restart IIS using iisreset command line and wait for success message.

Re-Crawl

Make sure that you Full Crawl !!!

*** Troubleshooting ***

Important step that will solve this error message "The filtering process could not process this item. This might be because you do not have the latest file filter for this type of item. Install the corresponding filter and retry your crawl."

Make sure to change the \\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.pdf to the GUID {E8978DA6-047F-4E3D-9C78-CDBE46041603}. The original value was {4C904448-74A9-11D0-AF6E-00C04FD8DC02}. (thanks to Russell Wright for that one)

URLs:

http://download.adobe.com/pub/adobe/acrobat/win/9.x/PDFiFilter64installer.zip
http://www.adobe.com/support/downloads/detail.jsp?ftpID=4025
http://support.microsoft.com/default.aspx/kb/832809
http://www.adobe.com/special/acrobat/configuring_pdf_ifilter_for_ms_sharepoint_2007.pdf
http://www.adobe.com/images/pdficon_small.gif
http://sharepointsolutions.blogspot.com/2009/01/installing-adobes-64-bit-pdf-ifilter-9.html

Thursday, March 5, 2009

WebService "Service Unavailable" error message

When changing the application pool user it is important to add the user to the IIS_WPG group.

Yesterday, we so this error message and found the solution here which says that the reason for this kind of error message may be because one of the following occurs:
  1. The application pool is not running.
  2. The application pool account uses an incorrect password.
  3. The application pool account is not a member of both the IIS_WPG group and the STS_WPG group on the server.

In our case it was the third one, after adding the application pool user to the IIS_WPG group the WebService run like a magic.....

Wednesday, March 4, 2009

MOSS S.W.A.T Blog

Hi All,

Just wanted to let you all know about a new blog i'm involved in...
The promising MOSS S.W.A.T Blog running by a highlly experiance MOSS team , I'm bribed cause it's my team :-) , but you can check it out and add it to your "Favorites" folder since there are new posts on daily basis.

In Moss We Trust : http://mosswat.blogspot.com/

I hope it would be interesting and handy.

Liron

Wednesday, January 23, 2008

Off Topic:Guten Morgen Germany

That is good morning in German, the weather is ok, and the food is fine (lots of sausages and beer)...

I'm staying in Darmstadt, located a little south of Frankfurt.
Got here to participate in two webMethods courses at SoftwareAG (yep, I know...it's not part of the MS technology) and till now it's interesting and easy.



Darmstadt is a small city and most pedestrians don't speak English and guess what - my German is not so good either....so it's a little bit difficult to manage around.

I'm planning to visit here the original Castle Frankenstein and to visit Heidelberg on the weekend.

If you happend to see me down the street....say hi :-)

Wednesday, January 16, 2008

MOSS Search for emails and attachments context

Some of our customers requested to have the ability to search context within email messages and within its attachments.

Searching the web for a solution came with results that indicate that a third-party development is needed to achieve this ability...
Then I found Gavin Adams post and Tom Vandaele post that wrote that the ability to deep search within msg files is a MOSS out-of-the-box option that need to be configure.

Followed their instructions I tried to search context in a docx file attachment with in a msg file that was uploaded to a document library. I succeed to get the msg file by searching its context , but failed to get results related to the email's attachments.

After some tests of my own, I figure out that the registry should look like that:
  1. Make sure that this key exists in the MOSS registry
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\12.0\Search\Setup\ContentIndexCommon\Filters\Extension\.msg
  2. Add these keys and values to the .msg
    “Extension”=”msg”
    “FileTypeBucket”=dword:00000001
    “MimeTypes”=”application/msoutlook”


The MimeTypes application/msoutlook is the one I use to gain the deep search ability (couldn't do it using the MimeTypes = application/vnd.ms-outlook)


A note to those of you using hebrew documents, I checked it and it's working for hebrew attachments as well.

Lirliron

Sunday, January 13, 2008

File size limitation

Hi all,

Lately I faced a problem when tried to upload a huge size file and got an Oversize limitation error message,
searching the SharePoint administration came out with nothing.

I found the solution within the STSADM.EXE:

stsadm -o setproperty -propertyname max-file-post-size -propertyvalue 120 -url http://myportalserver/

The propertyvalue represent a numerical value, in megabytes (MB).

Make sure to set the site size limitation as well.

Monday, August 27, 2007

Send Link By Email - Broken URL

For a few weeks, we are facing a problem when trying to send a link to a document from the document library (This occurs only for documents with a non English file name).
Clicking on the "Send To-> Send Link By Email" opens the new message window, but with a broken URL to the document.



Last night I cleared some time for this issue. After searching the MOSS javascripts I found the solution !!!
Within the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1037 Directory (1037 is for the Hebrew version) there is a js file named CORE.JS, inside is located the AddSendSubMenu function, this function generate the "Send" sub-menu that appear when clicking on a list item.

In order to solve the broken URL problem, find this line:
fileUrl=escapeProperly(httpRootWithSlash.substr(0, slashLoc))+currentItemUrl;

And replace it with this line:
fileUrl=escapeProperly(httpRootWithSlash.substr(0, slashLoc))+currentItemEscapedFileUrl;


Save the file, and now after clicking the "Send Link By Email" .....


I hope this solution will be of use for you....

Sunday, August 26, 2007

SharePoint Server 2007 SDK including the new BDC Definition Editor

Microsoft just announced the update for SharePoint Server 2007 SDK: Software Development Kit

the highlight for this update is the new Business Data Catalog Definition Editor.

Here are few of the SDK features, new samples and tool are in bold:

· Business Data Catalog Samples and Utilities

o Microsoft Business Data Catalog Definition Editor

o Sample Pluggable SSO Provider

o WSHelloWorld Web Service

o WSOrders Web Service

o Excel Services User Defined Function Sample

o WSOrders Custom Proxy Sample

o Amazon Web Service Sample

o AdventureWorks Metadata Samples

o SAP Sample

· Document Management and Content Processing Samples

o Comment Scrub Document Converter

o Term Replacement Document Inspector

· Search Samples

o Sample Protocol Handler

o Custom Content Source

· Records Management and Policy Samples

o De-Duplication Router

o Document Integrity Verifier

o Records Center Web Service Console Application

o Search, Collect, and Hold Tool

o Sample Custom Barcode Generator

o IRM Document Protector

· Workflow Samples

o Custom Workflow Report Query Generator

o Custom Workflow Report XLSX Injector

o Visual Studio Workflow Templates

o Enterprise Content Management Workflow Activities

o List Item Activities

o Hello World Sequential Workflow

o State Based Approval Workflow

o Modification Workflow

o Replication and Contact Selector Workflow

o Intersystem Purchase Order

o Confidential Approval Workflow

o Group Approval Workflow

o Approval Workflow Sample

o Multi-Stage Workflow

o Server-side Collect Signatures Workflow

Friday, August 10, 2007

CAML Builder

I just bumped into a fine CAML Builder tool from the U2U site.
http://www.u2u.info/SharePoint/U2U%20Community%20Tools/U2U%20CAML%20Query%20Builder%202007%20RTM.zip

I used it and it's grate !!!

Have a nice weekend,
Liron

Wednesday, August 8, 2007

MOSS List Event Receiver Register application

We developed an ItemEventReceiver to do somthing whenever a list item is added to a list.

In order to register this ItemEventReceiver to a list I created a WinForm application that should run on the MOSS and should register the ItemEventReceiver assembly to the list.

The application has the abbility to add the ItemEventReceiver assembly to any of the list item's available Event Types.

This is a quite simple application:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using Microsoft.SharePoint;

namespace MOSSListEventRegister

{

public partial class MOSSListEventRegisterForm : Form

{

public MOSSListEventRegisterForm()

{

InitializeComponent();

}

private void MOSSListEventRegisterForm_Load(object sender, EventArgs e)

{

//Fill EventReceiverTypeCheckedListBox

EventReceiverTypeCheckedListBox.Items.Add("ItemAdded");

EventReceiverTypeCheckedListBox.Items.Add("ItemAdding");

EventReceiverTypeCheckedListBox.Items.Add("ItemAttachmentAdded");

EventReceiverTypeCheckedListBox.Items.Add("ItemAttachmentAdding");

EventReceiverTypeCheckedListBox.Items.Add("ItemAttachmentDeleted");

EventReceiverTypeCheckedListBox.Items.Add("ItemAttachmentDeleting");

EventReceiverTypeCheckedListBox.Items.Add("ItemCheckedIn");

EventReceiverTypeCheckedListBox.Items.Add("ItemCheckedOut");

EventReceiverTypeCheckedListBox.Items.Add("ItemCheckingIn");

EventReceiverTypeCheckedListBox.Items.Add("ItemCheckingOut");

EventReceiverTypeCheckedListBox.Items.Add("ItemDeleted");

EventReceiverTypeCheckedListBox.Items.Add("ItemDeleting");

EventReceiverTypeCheckedListBox.Items.Add("ItemUpdated");

EventReceiverTypeCheckedListBox.Items.Add("ItemUpdating");

}

private void RegisterButton_Click(object sender, EventArgs e)

{

SPSite site = null;

SPWeb web = null;

SPList myList = null;

try

{

site = new SPSite(SiteURLTextBox.Text);

web = site.OpenWeb();

myList = web.Lists[ListsNameComboBox.SelectedText];

for (int i = 0; i < EventReceiverTypeCheckedListBox.Items.Count; i++)

{

switch (EventReceiverTypeCheckedListBox.Items.ToString())

{

case "ItemAdded":

myList.EventReceivers.Add(SPEventReceiverType.ItemAdded, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemAdding":

myList.EventReceivers.Add(SPEventReceiverType.ItemAdding, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemAttachmentAdded":

myList.EventReceivers.Add(SPEventReceiverType.ItemAttachmentAdded, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemAttachmentAdding":

myList.EventReceivers.Add(SPEventReceiverType.ItemAttachmentAdding, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemAttachmentDeleted":

myList.EventReceivers.Add(SPEventReceiverType.ItemAttachmentDeleted, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemAttachmentDeleting":

myList.EventReceivers.Add(SPEventReceiverType.ItemAttachmentDeleting, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemCheckedIn":

myList.EventReceivers.Add(SPEventReceiverType.ItemCheckedIn, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemCheckedOut":

myList.EventReceivers.Add(SPEventReceiverType.ItemCheckedOut, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemCheckingIn":

myList.EventReceivers.Add(SPEventReceiverType.ItemCheckingIn, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemCheckingOut":

myList.EventReceivers.Add(SPEventReceiverType.ItemCheckingOut, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemDeleted":

myList.EventReceivers.Add(SPEventReceiverType.ItemDeleted, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemDeleting":

myList.EventReceivers.Add(SPEventReceiverType.ItemDeleting, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemUpdated":

myList.EventReceivers.Add(SPEventReceiverType.ItemUpdated, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

case "ItemUpdating":

myList.EventReceivers.Add(SPEventReceiverType.ItemUpdating, AssemblyNameTextBox.Text, ClassNameTextBox.Text);

break;

}

}

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

finally

{

if (site != null)

{

site.Close();

site = null;

}

if (web != null)

{

web.Close();

web = null;

}

}

}

private void GetListsButton_Click(object sender, EventArgs e)

{

SPSite site = null;

SPWeb web = null;

SPList myList = null;

try

{

ListsNameComboBox.Items.Clear();

site = new SPSite(SiteURLTextBox.Text);

web = site.OpenWeb();

foreach (SPList lst in web.Lists)

{

if (!lst.Hidden )

ListsNameComboBox.Items.Add(lst.Title);

}

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

finally

{

if (site != null)

{

site.Close();

site = null;

}

if (web != null)

{

web.Close();

web = null;

}

}

}

}

}

Tuesday, July 31, 2007

BIO

Hi,

My name is Liron Leybovich and I'm a Senior .Net developer & a team leader in an Israeli IT Software company.
My first love affair was at the age of 8 with a Texas Instrument computer (no games cassette were included, only two "Basic" programming books…).
On My spare time I like to ride my mountain bike in the woods and to spend time with my wife and children.

I intend to write about technical issues regarding my experience as a .NET and Office System Developer.

Liron