Archive

Posts Tagged ‘SharePoint’

Updating the Version property of a field to the Version attribute in the fields SchemaXml

31 January 2013 Leave a comment

THIS IS VERY BAD. WE ALL KNOW THAT MAKING DIRECT UPDATES TO THE DATABASE WILL CREATE SOME SORT OF BLACK HOLE AND KITTENS DIE IN REDMOND ETC, ETC. I HAVEN’T TESTED THE LONG TERM EFFECTS AND ONLY DID THIS ON MY DEVELOPMENT ENVIRONMENT TO GET ME OUT OF A PICKLE.

Disclaimer over.

If you ever get this error when trying to update a field, either through the web UI or programmatic-ally  it normally means your Version fields are out of sync. This can occur if your field has been created using the Schema XML from another environment or you have migrated content using some dodgy 3rd party app.

Run this update on your content databases and you all should be good again.

UPDATE [MyContentDatabase].[dbo].[ContentTypes]
SET [Version] = CAST([Definition] AS XML).value('(/Field/@Version)[1]', 'int')
WHERE CAST([Definition] AS XML).value('(/Field/@Version)[1]', 'int') <> [Version]

Advertisements
Categories: Fix Tags: , , ,

Search the recycle bin with Powershell

17 October 2012 Leave a comment

Useful piece of Powershell to search for a file(s) / item(s) in the site recycle bin and then restore it/them.

Change the regular expression after match to change what files to search for.

$spsite = (Get-SPSite “http://mysite&#8221; )
$files = $spsite.RecycleBin | ?{$_.Title -match “myfile\d{2}”}

foreach ($file in $files) {

Write-Host “Found $($file.Title)”
$spsite.RecycleBin.Restore($file.ID)

}

Categories: Code Tags: , ,

“Hack attack” jQuery in a list view

9 July 2012 Leave a comment

Useful jQuery snippet to add a “View Properties” icon, so the user doesn’t have to use context menu or ribbon (apparently they prefer this)


$(".ms-listviewtable > tbody > tr:first").append("<TH class='ms-vh2 ms-vh2-icon' noWrap>View</TH>");
  
  $(".ms-listviewtable > tbody > tr").each(function() {
  
    if ($('td:first', $(this)).hasClass("ms-vb-title"))
    {
     var id = $("td.ms-vb-title > div.ms-vb", $(this)).attr("id");
     var viewLink = $("<td class='ms-vb-icon'><IMG style='CURSOR:hand; BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px' title='View Properties' alt=Search src='/_layouts/images/gosearch15.png' /></td>");      
     $(this).append(viewLink);
  
     viewLink.click(function(event){
         
      var options = {
       url: "/MyLibrary/Forms/DispForm.aspx?ID=" + id,
       title: "Document Properties",
       allowMaximize: true,
       showClose: true,
       dialogReturnValueCallback: function(dialogResult, returnValue) { }
      };
      
      SP.UI.ModalDialog.showModalDialog(options);
     });
    }
  });

This just adds an extra column to the end with an icon that opens the ‘View Properties’ dialog.

You can either use a Content Editor web part to make it view specific or add it to a global script for all views.
It’s a little hacky, but does the job.

It relies on the title column being available to extract the id of the item.

Categories: Code Tags: ,

Fun and games with the ActivityEvent

14 March 2011 2 comments

I haven’t seen a massive amount of documentation on MSDN or other posts about this, so I thought I would write a small note.

This details a way of extracting the info you see in the news feed on your ‘My Site’

First of all you need to get the the format used by the ActivityEvent, this done using ActivityType and ActivityTemplate.


ActivityType type = activityMan.ActivityTypes[activity.ActivityEventId];
ActivityTemplate template = type.ActivityTemplates[ActivityTemplatesCollection.CreateKey(false)];
string format = GetResourceString(template.TitleFormatLocStringResourceFile, template.TitleFormatLocStringName, (uint)CultureInfo.CurrentUICulture.LCID);

The format variable will now contain something along the lines of “{Pubisher} has posted a note {Link} on {PublishDate}”

Now you could at this point take the corresponding Properties in the ActivityEvent, but there is a whole load of formatting that needs to be done. The Publisher Tag needs to be turned into a link to the users profile page and display their name, etc, etc.

There is an easier way, you can use the static methods of the ActivityTemplateVariable.


ActivityTemplateVariable.DateOnlyToString(tag, variable, ContentType.Html, CultureInfo.CurrentCulture);

The problem here is that you have to pass in an ActivityTemplateVariable as one of the parameter and there is no obvious way of doing this.

There are no properties or methods in the ActivityEvent that give you an ActivityTemplateVariable or is there?

After further investigation of the TemplateVariable string property, you can see that this actually returns an XML string. This XML string is a de-serialised ActivityTemplateVariable object.


var variable = (ActivityTemplateVariable)FromXml(item.TemplateVariable, typeof(ActivityTemplateVariable));

You can now use this object to pass to the static method of ActivityTemplateVariable to return the full HTML representation of the tag.

If you then combine that with SimpleTemplateFormat you can then loop round all the tags and replace them.


var items = SimpleTemplateFormat.SimpleParse(formatToUse);

I’ll try and upload a code sample soon.