Saturday, August 1, 2009

Operation is not valid due to the current state of the object

I writed a post about this error (http://mosswat.blogspot.com/2009/02/operation-is-not-valid-due-to-current.html)

There is another cause to this error: using the "update" method in the "RunWithElevatePrivilege" scope, like this:

SPSecurity.RunWithElevatedPrivileges(delegate{
using (SPSite site = new SPSite("http://mySiteUrl"))
{
using (SPWeb web = site.OpenWeb())
{
SPListItem listItem = web.GetListItem("http://myItemUrl");
//do item modifications....
listItem.Update();
}
}

});

To resolve this issue, call the "update" method out of the "RunWithElevatedPrivileges" scope, like this;

SPSite site = null;
SPWeb web = null;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate{
site = new SPSite("http://mySiteUrl");
web = site.OpenWeb();
});
SPListItem listItem = web.GetListItem("http://myItemUrl");
//do item modifications....
listItem.Update();
}
finally
{
if (site != null)
site.Dispose();
if (web != null)
web.Dispose();
}

Wednesday, July 22, 2009

Active Directory: How to get all related groups by user

Hi

I know this is not a Moss post and i know that in Moss we trust, but it is a nice code to have.

Recently i needed to get all related AD groups per user, so if a user A is in group B and group B is in group C, i will get a collection like so { B,C } for A.

To do so i used the following code:


/// ldapPath - Ldap://...
/// distinguishedName - The user location (CN=AAA, OU=BBB,OU=CCC,DC=DDD )
///resultField - The property field value (DisplyName, Mail)
public static void GetAllRelatedGroupsByEntry(string ldapPath, string distinguishedName,
ref List<string> groups, string resultField)
{
SearchResultCollection results = null;

using (DirectoryEntry entry = new DirectoryEntry(ldapPath))
{

using (DirectorySearcher search = new DirectorySearcher(entry))
{

search.Filter = "(&(objectClass=Group)(objectCategory=Group)(member=" + distinguishedName + "))";

results = search.FindAll();

if (results != null)
{
foreach (SearchResult result in results)
{
for (int i = 0; i <>
{
groups.Add(result.Properties[resultField][i].ToString());
GetAllRelatedGroupsByEntry(ldapPath,
result.Properties["DistinguishedName"][i].ToString(),
ref groups, resultField);
}
}
}
}
}
}

Sunday, July 12, 2009

How to add Sharepoint Workflow Activities to Toolbox

Hi

There are more workflow activities that you can use beside the one that are already in, for example "Create Task".

To add them to the toolbox you need to open visual studio and on the Toolbox section:

1. Create new tab by right click and select "Add Tab".

2. Under the new tab press right click and select "Choose Items…" (It will take a while to open).

3. Then select microsoft.sharepoint.WorkflowActions.dll, it is usually under C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI

4. Press OK.

5. Now you will have the following activities:


Monday, July 6, 2009

SPWeb.RoleDefinitions.GetByType(SPRoleType.None)

Hi all

Recently i tried to copy permission from one item to another (see How To Copy Permissions Between Site Collections) , and had a problem with role definition types that were None.
The problem occured when i tried to copy
Restricted Read role agginment.

So to solve it I used this code:

if (roleDefinition.Type != SPRoleType.None)
{
definition = web.RoleDefinitions.GetByType(roleDefinition.Type);
roleAssignment.RoleDefinitionBindings.Add(definition);
}
else
{
definition = web.RoleDefinitions.GetById(roleDefinition.Id);
roleAssignment.RoleDefinitionBindings.Add(definition);
}

Instead of geting the code by role definition type i got it by it's Id.

Wednesday, May 6, 2009

How to create your own local path

Hi

In lots of MOSS development we are using custom aspx/html or just office templates and we need to save them in the local server file system. We can use the layouts folder (/_layouts/...) or create our own path.

To do so create a feature.xml and element.xml, in the element file add the Module tab, in the SetupPath attribute write the file system folder path (like FEATRUES\mosswat), and in the Url attribute write the new url (like _mosswat/templates).



Run the stsadm segment.

Now enter in the explorer the following: http://WebApp/sites/SiteCollection/_mosswat/templates/filename.docx


Tuesday, May 5, 2009

MOSS & AJAX (Framework 3.5)

Hi,

More and more sites are using AJAX and it is not only "nice to have" feature but a mandatory one.

We can also use AJAX in MOSS and there is a lot of example how to on the Internet, but before we start we have to add some elements in MOSS web.config.

A few posts ago Michael wrote on how to update web config, so i added the XML file in here so u can copy it to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\config and run the stsadm commend

Warnings:
  1. Before u run it backup your web.config and your DB and do not delete the element by your self only with the remove file.
  2. Don't copy the remove and the add together to the Config directory only the one you want to run.
  3. Very important don't change the guid before you are doing remove!!! 

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

How to easy add Dll to the gac

Hi,

If you want to add dll to the gac with a simple right click, follow theses steps:

1. Foreach .NET version paste the apropriate script in a new file
2. Save it with ".reg" extension
3. Double click on each file to add the entry in the registery.

.Net 1.1

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\dllfile\shell\gacutil\command]@="c:\\windows\\Microsoft.NET\\Framework\\v1.1.4322\\gacutil.exe /i \"%1\""

.Net 2.0

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\dllfile\shell\gacutil\command]@="C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\V2.0\\Bin\\gacutil.exe /i \"%1\""


Thanks to Elad R...

Tuesday, March 10, 2009

New Release Content Type List Binder

Hi all,

We have done it again... :)

Content Type List Binder is a new application that help us bind between lists and content types.

How to:

1. Enter the site collection url and press the load data button.
2. Select the lists you want (or need) and the relavent content type.
3. Press on bind (check the insert content type radio button to add and remove content type to remove).

You can Download Here (If you are like me and use Chrome it will save the file as .htm, so just change the suffix to .msi).

Saturday, March 7, 2009

SPQuery syntax

SPQuery is the best way to write queries on MOSS.
MOSS is using CAML to get data in the best and quickest way from sites,lists and folder. using SPQuery is in most cases the "best practice" way to find information in MOSS and also used in Sharepoint web services.
We have gather a few impotent information about SPQuery syntax,


Properties:
  • SPQuery.Query:




  • SPQuery.RowLimit: An int that indicate the row limit.



  • SPQuery.Folder: Get a SPFolder object.  
    This is the best way to get items that are in folder.
  • SPQuery.ViewField: The same is a "SELECT" sentence.





Operators:

Eq = equal to

Neq = not equal to

BeginsWith = begins with

Contains = contains

Lt = less than

Leq = less than or equal to

Gt = greater than

Geq = greater than or equal to

IsNull = is null

IsNotNull = is not null



AND & OR CONDITIONS

Using and & or is very similar to using regular parentheses, between each to operation we need to add AND or OR for example:

  • AND:


We are using AND between 2 operators and add another tab when we add a new operator.

  • OR:


The same as AND.

  • AND & OR:


With AND & OR we are creating brackets, we create each one of the conditions and wrap them with AND/OR.


How to write CAML queries ?

A very useful tool allow you to build yours CAML queries: U2U Caml Query Builder.



Performance consideration:

If your farm is well indexed, retiewing datas using SPquey in the best method to improve performance. See also our post about working with large list in Sharepoint