CAML query not considering time for Date and time field

Filed Under (Programming, SharePoint) by Boris Gomiunik on 29-10-2009

If you’re having trouble constructing your CAML query and you have a DateTime field with time enabled, the important fact that plain <Value Type="DateTime">2009-10-28T10:00:00Z</Value> will ignore the time part of the query. It is useful for querying whole days. If Time part of the DateTime field is also important to consider (you’re querying specific time of the day, you have to add parameter IncludeTimeValue="TRUE" parameter. So the whole CAML node would be

<Value IncludeTimeValue="TRUE" Type="DateTime">2009-10-28T10:00:00Z</Value>

Thanks, ucsharp for publishing this.

MOSS Lanugage pack installation without CD/DVD

Filed Under (CodePlex, DHTML, Programming, Software) by Boris Gomiunik on 14-09-2009

MOSS 2007 Lanugage Pack comes in .img format, which you can burn to a CD and then use it for installing Language pack. If you’re working remotely or working with a server that has no CD/DVD drive, this might pose a slight problem.

You can avoid this in a simple way:

1. Rename the .img file into an .iso file.

2. Download 7-zip portable version and extract the executable to a folder on your server desktop.

3. Navigate to the extracted folder and run 7-ZipPortable.exe.

4. Browse and open (double-click) the renamed .iso file
image

5. You can extract all files from the .iso to another folder on your desktop
image

Now you can browse to that folder and run the setup of language pack with no problem.

SPSecurity.RunWithElevatedPrivileges and Access Denied error on event receiver

Filed Under (C#, Programming, SharePoint) by Boris Gomiunik on 02-04-2009

After looksing half a day for a st00pid mistake I have to write about this to warn anyone that might run into similar problem.

In VS I’ve prepared a custom event receiver which needed to be run as system account (for performing actions that the user running the event receiver doesn’t have – like setting permissions, creating subwebs,…)

So my code began with something lilke that:

public override void ItemUpdated(SPItemEventProperties properties)
        {
            base.ItemUpdated(properties);
            _properties = properties;

            //povišamo pravice na sistemski račun in zaženemo private metodo
            SPSecurity.RunWithElevatedPrivileges(doSomethingWithThis);
        }

        private void doSomethingWithThis()
        {

            SPSite site = new SPSite(_properties.SiteId);
            SPWeb web = site.OpenWeb(_properties.RelativeWebUrl);
            SPListItem item = web.Lists[_properties.ListItem]

after running it and tracing the error I’ve always received “Access denied” error. How come, if I’m running the code with elevated privileges. Do I need even a higher privilege?

After countless attempts to impersonate an administrator or app pool account (I’m still a rookie at this), I’ve discovered that the SPItemEventProperties are instantiated with privileges of user that triggered the event receiver. The error was in my last line (of the example above) — _properties.ListItem still holds the rights of the original user. so fixed my code to

public override void ItemUpdated(SPItemEventProperties properties)
        {
            base.ItemUpdated(properties);
            _properties = properties;

            //povišamo pravice na sistemski račun in zaženemo private metodo
            SPSecurity.RunWithElevatedPrivileges(ustvariPonudbaSubsite);
        }

        private void ustvariPonudbaSubsite()
        {

            SPSite site = new SPSite(_properties.SiteId);
            SPWeb web = site.OpenWeb(_properties.RelativeWebUrl);
            SPListItem item = web.Lists[_properties.ListId].GetItemById(_properties.ListItem.ID);

With that change I’ve open the SPListItem object as system account and magically everything started working as it should! The same goes for site and web object. If you need to run actions with elevated privileges on SPSite and SPWeb object use

new SPSite(_properties.SiteId);
and
site.OpenWeb(_properties.RelativeWebUrl)

instead of

_properties.web
and
web.site;

ads
ads
ads