Syrinx on SharePoint

Syrinx SharePoint Team Blog
Need help on your project? info@syrinx.com, or toll free (888) 579-7469, press 1

News



Need help with your SharePoint project?

Syrinx works with clients throughout New England and across the United States to architect, design, develop, and deploy SharePoint implementations. Working on fully outsourced projects, as part of your team, helping to train your team, or rescuing projects in trouble, we are comfortable doing it all. Projects from a couple weeks to several months in duration, reference clients available. Contact us today - info@syrinx.com, or toll free (888) 579-7469 and press 1 to speak to someone now!

August 2008 - Posts

MOSS Search Part 3 - Authoritative Pages

In this part of the series we will take a look at setting up authoritative pages, which allows influencing the order of results coming from different content sources. You can specify which pages have higher or lower priority when appearing in the search results by providing a rank for pages or sites.

To add a site/page to Authoritative (or non-authoritative - demoted) pages:

  1. Go to Sharepoint Administration Site and click on the link under "Shared Services Administration" in the "Quick Launch" panel to open the Shared Services web site. image
  2. Open the Search Settings page by clicking on the Search Settings link in the Search section of Shared Services site
  3. In the Authoritative Pages section follow the Specify Authoritative Pages link image
  4. Fill out the Specify Authoritative Pages form providing the URL's for sites/pages having most and least influence on the order of search results.
    1. Most Authoritative sites: http://mysite.com/most_important_site
    2. Least Authoritative sites: http://mysite.com/dont_care_about_search.aspx 
  5. Press "Ok" to save results.
Running code inside MOSS with elevated permissions

Last week I was working on a simple web part that  would get come data from an MS SQL database and show in a grid. Per client's infrastructure requirements the connection to the sql server might only be done using integrated security, as sql users are not allowed to be created/used. By default, if you specify "Trusted_Connection = true", one of three things would happen: if the user is accessing the web site locally (the same server the MOSS WFE is running), her credentials will be used to connect to the SQL server; if the user is accessing the web site from the remote computer then depending on whether KerberOS authentication is turned on on the network either the user credentials or NT AUTHORITY/ANONIMOUS USER will be used for connection. Neither would not work in our case as the network team refused to enable KerberOS; after some research and with a hint from our inhouse MOSS guru Ryan Thomas I found that MOSS API gives you a way of executing a piece of code as the user running MOSS application pool; the way of doing it is in fact as easy as invoking a delegate;

you need to pass a delegate to a method containing your code to  SPSecurity.RunWithElevatedPrivileges() method; it's even easier when using anonymous delegates feature of C# 2.0:

SPSecurity.RunWithElevatedPrivileges(new SPSecurity.CodeToRunElevated(delegate()

{

... your code to connect to SQL server ...

}));

And all you have left to do is to configure appropriate permissions for the App Pool user on the SQL server.

 

Posted: Aug 11 2008, 11:45 AM by AndreyL | with no comments
Filed under:
CAML query to select items assigned to current user.

So after much googling and trying all the suggestions at

http://forums.msdn.microsoft.com/en-US/sharepointworkflow/thread/e8891d49-1d82-422e-8c7f-eb99326ec14c

We found the way to select from a list where the Assigned To user is the current user by building a view that has a filter criteria of Assigned To = [Me]. From this we got a reference to the SPView object for that view and then looked at the .Query specified:

 Our resulting code:

SPQuery qry;
qry.Query = "<Where><Eq><FieldRef Name=\"AssignedTo\" /><Value Type=\"Integer\"><UserID Type=\"Integer\" /></Value></Eq></Where>";

Hope this helps someone else save the hours we spent.

CAML queries with dates

Recently I was working on a utility that would query a MOSS list for items with update_timestamp field within a certain range. I used CAML queries for the task and this is when I found out that for dates in CAML  query filter the time part gets omitted, i.e. following two CAML queries will return the same results even though time part of the date is different:

<Query>
    <Where>
        <Geq>
            <FieldRef Name='Update_Timestamp' />
                <Value Type='DateTime'>2008-07-14T00:00:00Z</Value>
        </Geq>
    </Where>
</Query>

-----  and ----

<Query>
    <Where>
        <Geq>
            <FieldRef Name='Update_Timestamp' />
                <Value Type='DateTime'>2008-07-14T08:31:00Z</Value>
        </Geq>
    </Where>
</Query>

 

After some googling I found that the solution for this problem is to add "IncludeTimeValue" argument:

<Value Type='DateTime' IncludeTimeValue='TRUE' >2008-07-14T08:31:00Z</Value> 

 

Another problem I have been facing is how to include a dynamic date filter that is evaluated at runtime instead of hardcoding the dates, e.g. I want to include items with update_timestamp 5 days back or newer, something like Today() - 5. As I discovered, there is a CAML operator that does just that:

Instead of specifying a date you can do following:

<Query>
    <Where>
        <Geq>
            <FieldRef Name="Update_Timestamp" />
            <Value Type="DateTime">
                <Today OffsetDays="-5" />
            </Value>
        </Geq>
    </Where>
</Query>

 

And a closing tip: to create a sharepoint-formatted date string from a DateTime object you can use SPUtility.CreateISO8601DateTimeFromSystemDateTime() method.